maxgui.bmx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ' maxgui.bmx
  2. ' from minib3d examples (Based on code by Birdie and Peter Scheutz)
  3. Import "../openb3dlib.bmx"
  4. ?Linux
  5. Import bah.gtkmaxgui
  6. ?Not Linux
  7. Import maxgui.drivers
  8. ?
  9. Strict
  10. SetGraphicsDriver GLMax2DDriver() ' needed before CreateCanvas in Windows
  11. Local win:TGadget=CreateWindow("MiniB3D in a GUI window", 10, 10, 512, 512 )
  12. Local can:TGadget=CreateCanvas(0,0,ClientWidth(win),ClientHeight(win),win,0)
  13. SetGadgetLayout can,1,1,1,1
  14. SetGraphics CanvasGraphics(can)
  15. Graphics3D ClientWidth(win),ClientHeight(win),0,2,60,-1,True ' true if using a canvas context
  16. Local cam:TCamera=CreateCamera()
  17. PositionEntity cam,0,0,-10
  18. Local light:TLight=CreateLight(1)
  19. Local tex:TTexture=LoadTexture("media/test.png")
  20. Local cube:TMesh=CreateCube()
  21. Local sphere:TMesh=CreateSphere()
  22. Local cylinder:TMesh=CreateCylinder()
  23. Local cone:TMesh=CreateCone()
  24. PositionEntity cube,-6,0,0
  25. PositionEntity sphere,-2,0,0
  26. PositionEntity cylinder,2,0,0
  27. PositionEntity cone,6,0,0
  28. EntityTexture cube,tex
  29. EntityTexture sphere,tex
  30. EntityTexture cylinder,tex
  31. EntityTexture cone,tex
  32. Local cx#=0
  33. Local cy#=0
  34. Local cz#=0
  35. Local pitch#=0
  36. Local yaw#=0
  37. Local roll#=0
  38. ' used by fps code
  39. Local old_ms%=MilliSecs()
  40. Local renders%, fps%
  41. Local up_key%, down_key%, left_key%, right_key%
  42. CreateTimer(60)
  43. While True
  44. WaitEvent()
  45. Select EventID()
  46. Case EVENT_KEYDOWN
  47. Select EventData()
  48. Case KEY_ESCAPE
  49. End
  50. Case KEY_UP
  51. up_key=True
  52. Case KEY_DOWN
  53. down_key=True
  54. Case KEY_LEFT
  55. left_key=True
  56. Case KEY_RIGHT
  57. right_key=True
  58. EndSelect
  59. Case EVENT_KEYUP
  60. Select EventData()
  61. Case KEY_UP
  62. up_key=False
  63. Case KEY_DOWN
  64. down_key=False
  65. Case KEY_LEFT
  66. left_key=False
  67. Case KEY_RIGHT
  68. right_key=False
  69. EndSelect
  70. Case EVENT_WINDOWCLOSE
  71. End
  72. Case EVENT_WINDOWSIZE
  73. GraphicsResize(ClientWidth(win),ClientHeight(win)) ' update width/height values
  74. CameraViewport(cam,0,0,ClientWidth(win),ClientHeight(win)) ' set camera size
  75. DebugLog "EVENT_WINDOWSIZE"
  76. Case EVENT_TIMERTICK
  77. If up_key Then cz#=cz#+1.0
  78. If left_key Then cx#=cx#-1.0
  79. If right_key Then cx#=cx#+1.0
  80. If down_key Then cz#=cz#-1.0
  81. MoveEntity cam,cx#*0.5,cy#*0.5,cz#*0.5
  82. RotateEntity cam,pitch#,yaw#,roll#
  83. cx#=0
  84. cy#=0
  85. cz#=0
  86. RedrawGadget can
  87. Case EVENT_GADGETPAINT
  88. SetGraphics CanvasGraphics(can)
  89. TurnEntity cube,0,1,0
  90. RenderWorld
  91. Flip
  92. EndSelect
  93. Wend