December 04, 2020, 11:21:59 AM

Author Topic: [bmx] wxMax + minib3d by Warner [ 1+ years ago ]  (Read 737 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] wxMax + minib3d by Warner [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : wxMax + minib3d
Author : Warner
Posted : 1+ years ago

Description : Not sure if this is the best way to do this, but this is how I got this to work.

Code :
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Framework wx.wxApp
  4. Import wx.wxFrame
  5. Import wx.wxPanel
  6. Import wx.wxGLCanvas
  7. Import wx.wxglmax2D
  8.  
  9. Import wx.wxTimer
  10.  
  11. Import sidesign.minib3d
  12.  
  13. 'Since i want to call 'refresh' from inside the timer, i need to store
  14. 'this handle. That way i can address 'prog.canvas'
  15. Global prog:MyApp = New MyApp
  16. prog.Run()
  17.  
  18. Type MyApp Extends wxApp
  19.  
  20.         Field frame:wxFrame
  21.         Field panel:wxPanel
  22.         Field canvas:TMiniB3D
  23.  
  24.         Method OnInit:Int()
  25.  
  26.                 'create a 640x480 window
  27.                 frame = New wxFrame.Create(,,"MiniB3d Sample", 0, 0, 640, 480)
  28.                 frame.Center()
  29.                
  30.                 'create a 320x240 wxPanel
  31.                 panel = New wxPanel.Create(frame, wxID_ANY, 160, 0, 320, 240)
  32.                 'create wxGLCanvas with minib3d on it
  33.                 canvas = TMiniB3D(New TMiniB3D.Create(panel, wxID_ANY, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER, 0, 0, 320, 240))
  34.  
  35.                 'create timer
  36.                 Local timer:wxTimer = MyTimer(New MyTimer.Create())
  37.                 timer.Start(25)
  38.                                                                
  39.                 frame.show()                           
  40.  
  41.                 Return True
  42.        
  43.         End Method
  44.                        
  45. End Type
  46.  
  47. Type TMiniB3D Extends wxGLCanvas
  48.  
  49.         Field init:Int = 0
  50.                                
  51.         Method OnPaint(event:wxPaintEvent)
  52.        
  53.                 'this could be done better, i'm sure, but for me it was the only way it works
  54.                 'when onpaint is called, the canvas is valid and can be initialized by minib3d
  55.                 If init = 0 Then
  56.                
  57.                         'init minib3d
  58.                         SetGraphics CanvasGraphics2D( Self )
  59.                         TGlobal.width = 320
  60.                         TGlobal.height = 240
  61.                         TGlobal.depth = 32
  62.                         TGlobal.mode = 2
  63.                         TGlobal.GraphicsInit()
  64.                         init = 1
  65.  
  66.                         'function for creating camera's etc.                   
  67.                         InitMB3D()
  68.                        
  69.                 End If
  70.  
  71.                 'after that, every time onpaint is called, the scene can be rendered
  72.                 RenderMB3D()
  73.  
  74.         End Method
  75.  
  76. End Type
  77.  
  78. Global cam:TCamera
  79. Global cube:TEntity
  80.  
  81. 'setup camera and cube
  82. Function InitMB3D()
  83.  
  84.         cam  = CreateCamera()
  85.         cube = CreateCube()
  86.         MoveEntity cam, 0, 0, -5
  87.        
  88.         EntityTexture cube, LoadTexture("C:Program FilesBlitzMaxdocshtmlmax120.png") 'hopefully you have this file too
  89.         EntityFX cube, 1
  90.        
  91.         RenderWorld 'i need to do this in my modded version of minib3d, i don't think it is needed in the orig. version
  92.  
  93. End Function
  94.  
  95. 'render stuff
  96. Function RenderMB3D()
  97.  
  98.         RenderWorld
  99.        
  100.         BeginMax2D 'max2d works as well
  101.         DrawText "hello", 0, 0
  102.         EndMax2D
  103.        
  104.         Flip
  105.  
  106. End Function
  107.  
  108. 'timer
  109. Type MyTimer Extends wxTimer
  110.  
  111.         Field count:Int
  112.  
  113.         Method Notify()
  114.                 TurnEntity cube, 1, 2, 3 'turn cube
  115.                 prog.canvas.Refresh() 'render scene
  116.         End Method
  117.  
  118. End Type


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal