CreateTexture.bmx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ' CreateTexture.bmx
  2. ' from Blitz3D help
  3. Strict
  4. Framework b3d.b3dglgraphics
  5. Graphics3D 800,600,0,2
  6. Local camera:TCamera=CreateCamera()
  7. Local light:TLight=CreateLight()
  8. RotateEntity light,90,0,0
  9. Local cube:TMesh=CreateCube()
  10. PositionEntity cube,0,0,5
  11. ' Create texture of size 256x256
  12. Local tex:TTexture=CreateTexture(256,256)
  13. BeginMax2D()
  14. ' Clear texture buffer with background white color
  15. SetClsColor 255,255,255
  16. Cls
  17. ' Draw text on texture
  18. Local font:TImageFont=LoadImageFont("arial",24)
  19. SetImageFont font
  20. SetColor 0,0,0
  21. DrawText "This texture",0,0
  22. DrawText "was created using",0,40
  23. SetColor 0,0,255
  24. DrawText "CreateTexture()",0,80
  25. SetColor 0,0,0
  26. DrawText "and drawn to using",0,120
  27. SetColor 0,0,255
  28. DrawText "GrabPixmap() and BufferToTex()",0,160
  29. EndMax2D()
  30. Local pix:TPixmap=GrabPixmap(0,0,256,256)
  31. If PixmapFormat(pix)<>PF_RGBA8888 Then pix=ConvertPixmap(pix,PF_RGBA8888)
  32. BufferToTex(tex,PixmapPixelPtr(pix,0,0))
  33. EntityTexture cube,tex
  34. While Not KeyDown(KEY_ESCAPE)
  35. Local pitch#=0
  36. Local yaw#=0
  37. Local roll#=0
  38. If KeyDown( key_down )=True Then pitch#=-1
  39. If KeyDown( key_up )=True Then pitch#=1
  40. If KeyDown( key_left )=True Then yaw#=-1
  41. If KeyDown( key_right )=True Then yaw#=1
  42. If KeyDown( key_z )=True Then roll#=-1
  43. If KeyDown( key_x )=True Then roll#=1
  44. TurnEntity cube,pitch#,yaw#,roll#
  45. RenderWorld
  46. Flip
  47. Wend
  48. End