tex_render.bb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Global info1$="Texture render demo"
  2. Global info2$="Renders a 3D scene onto a texture"
  3. Global info3$="Use Arrow keys to Pan, A/Z to zoom"
  4. Include "../start.bb"
  5. grid_tex=CreateTexture( 16,16,8,1 )
  6. ScaleTexture grid_tex,10,10
  7. SetBuffer TextureBuffer( grid_tex )
  8. ClsColor 255,255,255:Cls:ClsColor 0,0,0
  9. Color 192,192,192:Rect 0,0,8,8:Rect 8,8,8,8
  10. SetBuffer BackBuffer()
  11. plane=CreatePlane()
  12. EntityTexture plane,grid_tex
  13. pivot=CreatePivot()
  14. PositionEntity pivot,0,2,0
  15. t_sphere=CreateSphere( 8 )
  16. EntityShininess t_sphere,.2
  17. For t=0 To 359 Step 36
  18. sphere=CopyEntity( t_sphere,pivot )
  19. EntityColor sphere,Rnd(256),Rnd(256),Rnd(256)
  20. TurnEntity sphere,0,t,0
  21. MoveEntity sphere,0,0,10
  22. Next
  23. FreeEntity t_sphere
  24. texture=CreateTexture( 128,128 )
  25. cube=CreateCube()
  26. EntityTexture cube,texture
  27. PositionEntity cube,0,7,0
  28. ScaleEntity cube,3,3,3
  29. light=CreateLight()
  30. TurnEntity light,45,45,0
  31. camera=CreateCamera()
  32. plan_cam=CreateCamera()
  33. TurnEntity plan_cam,90,0,0
  34. PositionEntity plan_cam,0,20,0
  35. CameraViewport plan_cam,0,0,128,128
  36. CameraClsColor plan_cam,0,128,0
  37. d#=-20
  38. While Not KeyHit(1)
  39. If KeyDown(30) d=d+1
  40. If KeyDown(44) d=d-1
  41. If KeyDown(203) TurnEntity camera,0,-3,0
  42. If KeyDown(205) TurnEntity camera,0,+3,0
  43. PositionEntity camera,0,7,0
  44. MoveEntity camera,0,0,d
  45. TurnEntity cube,.1,.2,.3
  46. TurnEntity pivot,0,1,0
  47. UpdateWorld
  48. HideEntity camera
  49. ShowEntity plan_cam
  50. RenderWorld
  51. CopyRect 0,0,128,128,0,0,0,TextureBuffer( texture )
  52. ShowEntity camera
  53. HideEntity plan_cam
  54. RenderWorld
  55. Flip
  56. Wend