Ooops
October 28, 2020, 05:49:32 AM

Author Topic: [bb] 3D Desktop Cubes by Ziltch [ 1+ years ago ]  (Read 1235 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3D Desktop Cubes by Ziltch [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : 3D Desktop Cubes
Author : Ziltch
Posted : 1+ years ago

Description : Example of the GetDesktop Function (in Graphics section of Code archives).

NOTE: Only gets desktop in fullscreen. i.e debug off.
      See GetDesktop function code archives entry in
      Graphics section for userlib info you may need.


Code :
Code: BlitzBasic
  1. ; 3D Cubes  Desktop Sample
  2.  
  3. Const SRCCOPY = $CC0020
  4. Const CF_BITMAP = 2
  5. Const SW_HIDE = 0
  6. Const SW_SHOW = 5
  7.  
  8. Function GetDesktop(flag=0,update=0)
  9.  
  10. ; ADAmor ZILTCH 2003
  11. ;
  12. ; This command must come after your GRAPHICS(3D) x,y command.
  13. ;
  14. ;  flag 0 = create texture
  15. ;       1 = create image
  16.  
  17.    DeskHwnd = GetDesktopWindow()
  18.  
  19.    ; Get screen coordinates
  20.  
  21.    fwidth  = GetSystemMetrics%(0)
  22.    fheight = GetSystemMetrics%(1)
  23.  
  24.    BlitzHwnd = GetActiveWindow()
  25.    ShowWindow(BlitzHwnd,SW_HIDE)
  26.  
  27.    ; Get the device context of Desktop and allocate memory
  28.    hdc = GetDC(DeskHwnd)
  29.    Blitzhdc = GetDC(BlitzHwnd)
  30.  
  31.    ; Copy data
  32.    BitBlt(Blitzhdc, 0, 0, fwidth, fheight, hdc, 0,0, SRCCOPY)
  33.  
  34.    ; Clean up handles
  35.    ReleaseDC(DeskHwnd, hdc)
  36.    ReleaseDC(BlitzHwnd, Blitzhdc)
  37.    ShowWindow(BlitzHwnd,SW_SHOW)
  38.  
  39.    ; Create/update texture or image
  40.    Select flag
  41.      Case 0
  42.        If update = 0 Then
  43.          tex=CreateTexture(fwidth,fheight)
  44.        Else
  45.          tex=update
  46.        End If
  47.        CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),TextureBuffer(tex)
  48.        Return tex
  49.      Case 1
  50.        If update = 0 Then
  51.          image=CreateImage(fwidth,fheight)
  52.        Else
  53.          image=update
  54.        End If
  55.        CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),ImageBuffer(image)
  56.        Return image
  57.    End Select
  58.  
  59. End Function
  60.  
  61. ;--start sample code
  62.  
  63.  
  64. deskwidth=GetSystemMetrics(0);800
  65. deskheight=GetSystemMetrics(1);600
  66. Graphics3D deskwidth,deskheight
  67.  
  68.  
  69. cam=CreateCamera()
  70. PositionEntity cam,0,0,-4
  71. CameraClsMode  cam,False,True
  72.  
  73. l1=CreateLight(2)
  74. LightColor     l1,255,255,50
  75. LightRange     l1,300
  76. PositionEntity l1,-100,50,100
  77.  
  78. l2=CreateLight(2)
  79. LightColor     l2,255,200,100
  80. LightRange     l2,300
  81. PositionEntity l2,100,50,100
  82.  
  83. l3=CreateLight(2)
  84. LightColor     l3,255,100,255
  85. LightRange     l3,300
  86. PositionEntity l3,0,-50,-10
  87.  
  88. tex=CreateTexture(1024,1024,1)
  89. ScaleTexture tex,(1024/Float(deskwidth)),(1024/Float(deskheight))
  90.  
  91. cube1=CreateCube()
  92. EntityTexture  cube1,tex
  93. ScaleMesh      cube1,3,3,3
  94. GetDesktop(0,tex)
  95. image = getdesktop(1)
  96.  
  97. Type cube
  98.  Field ent
  99. End Type
  100.  
  101. For x = -200 To 200 Step 20
  102.   For z = -100 To 300 Step 20
  103.     a =a + 1
  104.     c.cube = New cube
  105.     cent= CopyEntity(cube1)
  106.     PositionEntity cent,x,Rand(-100,150),z
  107.     TurnEntity cent,Rand(360),Rand(360),Rand(360)
  108.     UpdateNormals cent
  109.   Next
  110. Next
  111.  
  112. HideEntity cube1
  113. FreeEntity cube1
  114.  
  115. SetBuffer BackBuffer()
  116. While Not GetKey()
  117.  
  118.   DrawBlock image,0,0
  119.   For tc.cube = Each cube
  120.     TurnEntity tcent,1,1,0
  121.     MoveEntity tcent,0,0,.1
  122.   Next
  123.  
  124.   TurnEntity cam,.05,.1,0
  125.   MoveEntity cam,0,0,.2
  126.  
  127.   ms = MilliSecs() Shr 2
  128.   AmbientLight Sin(ms)*128+127,Cos(ms)*128+127,Sin(ms*3.5)*Cos(ms*4.7)*128+127
  129.  
  130.   RenderWorld
  131.   Flip
  132. Wend
  133. End


Comments :


Ked(Posted 1+ years ago)

 Very cool.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal