Alternative to using a Timer for 3D Rendering?

BlitzMax Forums/Brucey's Modules/Alternative to using a Timer for 3D Rendering?

Chapman7(Posted 2012) [#1]
I was wondering what other methods there were for getting something to render in wxMax without using a timer. I made this thread the other day (http://blitzmax.com/Community/posts.php?topic=98458) to compare wxMax and MaxGUI when using MiniB3D but I needed someone to check the wxMax code.

I know its not as efficient as it could be, but I do not know another way I could go about rendering it. Any input on the matter would be greatly appreciated :)


Chapman7(Posted 2012) [#2]
Scratch that, here is the code:

SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxPanel
Import wx.wxGLCanvas
Import sidesign.minib3d


Global Cube:TMesh
Global old_ms:Int=MilliSecs()
Global renders:Int
Global fps:Int

Global prog:MyApp = New MyApp
prog.Run()

Type MyApp Extends wxAppMain
	Field frame:wxFrame
	Field panel:wxPanel
	Field canvas:TMiniB3D
	Global shouldExit:Int = False
	Method OnInit:Int()
		frame = New wxFrame.Create(,,"MiniB3d Sample", 0, 0, 512, 512)
		frame.Center()
		panel = New wxPanel.Create(frame, wxID_ANY, 0, 0, 512, 512)
		canvas = TMiniB3D(New TMiniB3D.Create(panel, wxID_ANY, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER, 0, 0, 512, 512))
		frame.show()				
		Return True
	End Method
	Method MainLoop:Int()
		While True
		While Not Pending() And ProcessIdle() ; Wend
		While Pending()
			If Not Dispatch() Then
				shouldExit = True
				Exit
			End If
		Wend
		If shouldExit Then
			While pending() 
				dispatch() 
			Wend
			Return 0
		End If

		TurnEntity cube, 0, 1, 0
		RenderWorld
		renders=renders+1
		If MilliSecs()-old_ms>=1000
			old_ms=MilliSecs()
			fps=renders
			renders=0
		EndIf
		Text 0, 0, "FPS: "+fps
		Flip

		Wend
	EndMethod
End Type

Type TMiniB3D Extends wxGLCanvas
	Field init:Int = 0
	Method OnPaint(event:wxPaintEvent)
		If init = 0 Then		
			SetGraphics CanvasGraphics( Self )
			TGlobal.width = 512
			TGlobal.height = 512
			TGlobal.depth = 16
			TGlobal.mode = 0
			TGlobal.GraphicsInit()
			init = 1		
			Local Camera:TCamera = CreateCamera()
			PositionEntity Camera, 0, 0, -10
			
			Local Light:TLight = CreateLight(1)
			cube:TMesh=CreateCube()
			Local sphere:TMesh=CreateSphere()
			Local cylinder:TMesh=CreateCylinder()
			Local cone:TMesh=CreateCone() 
			
			PositionEntity cube,-6,0,0
			PositionEntity sphere,-2,0,0
			PositionEntity cylinder,2,0,0
			PositionEntity cone,6,0,0
			RenderWorld
		End If
	End Method
End Type



btw if anyone knows what the difference is between wxApp and wxAppMain, I would really like to know. I know you cannot access a MainLoop in wxApp, but I dont know what else you can or cant access.