MiniB3D Thread 2

BlitzMax Modules Forums/MiniB3D/MiniB3D Thread 2

hate to ask again but maybe it was overlooked, can minib3d work inside a maxGUI canvas?


It can. Below is a quick hack to show it's possible. (put it in "tests" folder)

I'd really like MiniB3D support it natively.

SuperStrict
Import "../MiniB3D.bmx"
'based on Simple GL cube demo + simonh's primitives.bmx sample
'Written by Birdie


SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER

Global ax#, ay#,tim#

Local w:TGadget = CreateWindow("Easy Minib3d in a GUI window", 10, 10, 512, 512 )

Local c:TGadget = CreateCanvas(0,0,w.clientwidth(),w.clientheight(),w,0)
c.setlayout 1,1,1,1


''''''''''''''''''''''''''''''''
	TGlobal.width = w.clientwidth()
	TGlobal.height = w.clientheight()


	TGlobal.depth=16
	TGlobal.mode=0
	TGlobal.rate=60



	SetGraphics CanvasGraphics( c )

	TTexture.TextureFilter("",9)
		
	glewInit() ' required for glActiveTexture

	glEnable(GL_LIGHTING)
	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
		
	glEnable(GL_NORMALIZE)

	glEnable(GL_SCISSOR_TEST)
	
	glEnable(GL_DEPTH_TEST)
	glClearDepth(1.0)						
	glDepthFunc(GL_LEQUAL)
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

	glAlphaFunc(GL_GEQUAL,0.5)
			
	glEnableClientState(GL_VERTEX_ARRAY)
	glEnableClientState(GL_COLOR_ARRAY)
	glEnableClientState(GL_NORMAL_ARRAY)

	glLineWidth(4)





Local  cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-10

Local light:TLight=CreateLight(1)

Local tex:TTexture=LoadTexture("media/Rock.bmp")

Local 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

EntityTexture cube,tex
EntityTexture sphere,tex
EntityTexture cylinder,tex
EntityTexture cone,tex

Local cx#=0
Local cy#=0
Local cz#=0

Local pitch#=0
Local yaw#=0
Local roll#=0

' used by fps code
Local old_ms:Int=MilliSecs()
Local renders:Int
Local fps:Int

''''''''''''''''''''''''''''''''''

CreateTimer( 60 )

While True
        WaitEvent()
        Select EventID()
				Case EVENT_WINDOWCLOSE
                       End

				Case EVENT_WINDOWSIZE

					TGlobal.width = w.clientwidth()
					TGlobal.height = w.clientheight()


					cam.CameraViewport(0,0,w.ClientWidth() , w.clientheight())				
					DebugLog "EVENT_WINDOWSIZE" 

                Case EVENT_TIMERTICK
                        RedrawGadget c
 

                       
                Case EVENT_GADGETPAINT
					 SetGraphics CanvasGraphics( c )

					MoveEntity cam,cx#*0.5,cy#*0.5,cz#*0.5
					RotateEntity cam,pitch#,yaw#,roll#
					cx#=0
					cy#=0
					cz#=0

					TurnEntity cube,0,1,0
					
					cx#=0
					cy#=0
					cz#=0
					
					RenderWorld
					
					Flip
                                
        EndSelect
Wend