MiniB3D + GUI

BlitzMax Modules Forums/Brucey's Modules/MiniB3D + GUI

Hey, i'm doing a basic problem generator for finding volume of prisms ect..

I want to use minib3d for the graphics and I have a few questions:

1. Will minib3d work in combinations with wxMax?
2. How can I draw the canvas correctly? It seems to clear all the gadgets I lay down..

here's my code so far... (notice how it gets rid of the New problem button)

SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxGLCanvas
Import wx.wxTimer
Import wx.wxButton
Import wx.wxPanel
Import wx.wxglmax2D

Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC



' run
SetGraphicsDriver wxGLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
New MyApp.run()


Type MyApp Extends wxApp

	Field frame:MyFrame

	Method OnInit:Int()

		frame = MyFrame(New MyFrame.Create(Null,-1,"Mathematics - Measurements of 3d objects", 50, 50, 800, 600, wxDEFAULT_NO_RESIZE))

		frame.show()
		
		Return True
	
	End Method

End Type

Type MyFrame Extends wxFrame

	Field canvas:MyCanvas

	Method OnInit()
	
		canvas = MyCanvas(New MyCanvas.Create(Self, -1, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER, 0, 0, 350,600))
		Local panel:wxPanel = wxPanel(New wxPanel.Create(Self, 0, 0, 800, 600 ))
		Local bNewQuestion:wxButton = New wxButton.Create(panel,wxID_Ok,"New problem!",500,410)
	
	
		ConnectAny(wxEVT_CLOSE, OnClose)
	End Method
	
	Function OnClose(event:wxEvent)
		MyFrame(event.parent).canvas.timer.Stop()
		event.Skip()
	End Function

End Type

Type MyCanvas Extends wxGLCanvas

	Field timer:wxTimer

	Method OnInit()
		timer = New wxTimer.Create(Self)
		ConnectAny(wxEVT_TIMER, OnTimer)
		timer.Start(16)
	End Method

	Function OnTimer(event:wxEvent)
		MyCanvas(event.parent).Refresh()
	End Function
	
	Method OnPaint(event:wxPaintEvent)
		SetGraphics CanvasGraphics2D( Self )
		Flip
	End Method


End Type


I found the answer to the gadget problem - draw on the panel not the window... But the first question remains, how do you draw with minib3d?

Yes, I really would like at least someone to render a cube or something. This would help me out so much! I have worked on this for probably a day straight, and I have not gotten anything.

It's strange.... the glcube sample runs fine, and the code is very similar.
The code I posted HERE runs fine on the Mac, but on my XP at work it draws a mess...

If the canvas is a normal GL context, then it shouldn't really matter what UI environment it is being used in - as the glcube sample shows.
There must be some other things that MiniB3D is doing/expects that is missing here for some reason...

Yeah, I tried the example and it rendered nothing... odd. I'm using raw opengl for drawing for now.

Here's a question: How would I draw simple text on a GL canvas?

Have a look at the glmax2d sample for using the standard drawing commands on a canvas.

It doesnt seem to work - cls kills my raw opengl stuff

ah, indeed... you probably need to have a look at the minib3d code which toggles Max2D stuff on and off. It'll likely have the OGL commands to do it properly.

I got something to work well sort of.. it crashes like 15s into running...

Also, the text is gray?

here's an example:


SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxGLCanvas
Import wx.wxTimer
Import wx.wxPanel
Import wx.wxglmax2D

Const wxDEFAULT_NO_RESIZE:Int = wxSYSTEM_MENU | wxMINIMIZE_BOX | ..
wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN | wxBORDER_STATIC

Global ortho_mv![16],ortho_pj![16]

' run
SetGraphicsDriver wxGLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
New MyApp.run()

Type MyApp Extends wxApp

	Field frame:MyFrame

	Method OnInit:Int()

		frame = MyFrame(New MyFrame.Create(Null,-1,"Mathematics - Volume of 3d objects", 50, 50, 800, 600, wxDEFAULT_NO_RESIZE))

		frame.show()
		
		Return True
	
	End Method

End Type

Type MyFrame Extends wxFrame

	Field canvas:MyCanvas

	Method OnInit()
	
		Local panel:wxPanel = wxPanel(New wxPanel.Create(Self, 0, 0, 800, 600 ))
		canvas = MyCanvas(New MyCanvas.Create(panel, -1, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER, 0, 0, 350,600))
		
		ConnectAny(wxEVT_CLOSE, OnClose)
	End Method
	
	Function OnClose(event:wxEvent)
		MyFrame(event.parent).canvas.timer.Stop()
		event.Skip()
	End Function

End Type

Type MyCanvas Extends wxGLCanvas

	Field timer:wxTimer

	Field rot:Int

	Method OnInit()
		SetBackgroundStyle(wxBG_STYLE_CUSTOM)
		timer = New wxTimer.Create(Self)
		ConnectAny(wxEVT_TIMER, OnTimer)
		timer.Start(16)
	End Method
	

	Function OnTimer(event:wxEvent)
		MyCanvas(event.parent).Refresh()
	End Function
	
	Method OnPaint(event:wxPaintEvent)
		SetGraphics CanvasGraphics2D( Self )
		Local wid:Int, hgt:Int
		GetSize(wid, hgt)
		Local asp# = Float(wid)/Float(hgt)
		
		glViewport 0,0,wid,hgt
		glMatrixMode GL_PROJECTION
		glLoadIdentity
		gluPerspective 45, asp, 1, 100
		gltranslatef 0,0,-50
		
		glMatrixMode GL_MODELVIEW
		glLoadIdentity()
		
		Local global_ambient#[]=[1.0#, 1.0#,  1.0#, 1.0#]
		Local light0pos#[]=     [0.0#, 5.0#, 10.0#, 1.0#]
		Local light0ambient#[]= [0.5#, 0.5#,  0.5#, 1.0#]
		Local light0diffuse#[]= [0.3#, 0.3#,  0.3#, 1.0#]
		Local light0specular#[]=[0.8#, 0.8#,  0.8#, 1.0#]
		Local lmodel_ambient#[]=[ 0.2#,0.2#,0.2#,1.0#]
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient)
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient)
		glLightfv(GL_LIGHT0, GL_POSITION, light0pos)
		glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient)
		glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse)
		glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular)
		glMateriali(GL_FRONT, GL_SHININESS, 128)
		glEnable(GL_LIGHTING)
		glEnable(GL_LIGHT0)
		glShadeModel(GL_SMOOTH)
		glEnable(GL_DEPTH_TEST)
		
		
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

		'glRotatef(rot,.3,.6,1.0)
		DrawCube(3)
		'glLoadIdentity()
		
		BeginMax2d()
		DrawText "test text -- this should be white",0,0
		DrawText "test text -- this should be white",0,15
		DrawText "test text -- this should be white",0,30
		DrawText "test text -- this should be white",0,45
		DrawText "test text -- this should be white",0,60
		DrawText "test text -- this should be white",0,75
		DrawText "test text -- this should be white",0,90
		EndMax2d()
		
		rot:+1 ; If rot > 359 rot:-360
		Flip
	End Method
	
	Method DrawCube(size#)
	        size=-size
	        'Front Face
	        glBegin(GL_TRIANGLE_STRIP)
	                glNormal3f( 0.0, 0.0, 1.0)
	                glVertex3f( size, size,-size)
	                glNormal3f( 0.0, 0.0, 1.0)
	                glVertex3f(-size, size,-size)
	                glNormal3f( 0.0, 0.0, 1.0)
	                glVertex3f( size,-size,-size)
	                glNormal3f( 0.0, 0.0, 1.0)
	                glVertex3f(-size,-size,-size)
	        glEnd
	        'Back Face
	        glNormal3f( 0.0, 0.0, -1.0)
	        glBegin(GL_TRIANGLE_STRIP)
	                glVertex3f(-size, size, size)
	                glVertex3f( size, size, size)
	                glVertex3f(-size,-size, size)
	                glVertex3f( size,-size, size)
	        glEnd
	        'Right Face
	        glNormal3f( 1.0, 0.0, 0.0)
	        glBegin(GL_TRIANGLE_STRIP)
	                glVertex3f(-size, size,-size)
	                glVertex3f(-size, size, size)
	                glVertex3f(-size,-size,-size)
	                glVertex3f(-size,-size, size)
	        glEnd
	        'Left Face
	        glNormal3f( -1.0, 0.0, 0.0)
	        glBegin(GL_TRIANGLE_STRIP)
	                glVertex3f( size, size, size)
	                glVertex3f( size, size,-size)
	                glVertex3f( size,-size, size)
	                glVertex3f( size,-size,-size)
	        glEnd
	        'Bottom Face
	        glNormal3f( 0.0, -1.0, 0.0)
	        glBegin(GL_TRIANGLE_STRIP)
	                glVertex3f( size, size,-size)
	                glVertex3f( size, size, size)
	                glVertex3f(-size, size,-size)
	                glVertex3f(-size, size, size)
	        glEnd
	        'Top Face
	        glNormal3f( 0.0, 1.0, 0.0)
	        glBegin(GL_TRIANGLE_STRIP)
	                glVertex3f( size,-size,-size)
	                glVertex3f(-size,-size,-size)
	                glVertex3f( size,-size, size)
	                glVertex3f(-size,-size, size)
	    glEnd
	End Method

	

End Type

'--------------------------------------------------------------------------------------------------------


	' Function by Oddball
Function BeginMax2D()
	BeginOrtho()
	' set active texture to texture 0 so gldrawtext will work correctly
	glDisable(GL_LIGHTING)
	glDisable(GL_LIGHT0)
	glEnable(GL_BLEND)
		
	glPopClientAttrib
	glPopAttrib
	glMatrixMode GL_MODELVIEW
	glPopMatrix
	glMatrixMode GL_PROJECTION
	glPopMatrix
	glMatrixMode GL_TEXTURE
	glPopMatrix
	glMatrixMode GL_COLOR
	glPopMatrix 
	

End Function

	' Function by Oddball	
Function EndMax2D()
	
		' save the Max2D settings for later
	glPushAttrib GL_ALL_ATTRIB_BITS
	glPushClientAttrib GL_CLIENT_ALL_ATTRIB_BITS
	glMatrixMode GL_MODELVIEW
	glPushMatrix
	glMatrixMode GL_PROJECTION
	glPushMatrix
	glMatrixMode GL_TEXTURE
	glPushMatrix
	glMatrixMode GL_COLOR
	glPushMatrix 
		
	glDisable(GL_BLEND)
	
	EndOrtho()
End Function

Function BeginOrtho()
	Local vp:Int[4]
	
	glPushAttrib GL_ENABLE_BIT|GL_TEXTURE_BIT|GL_TRANSFORM_BIT
	
	glGetIntegerv GL_VIEWPORT,vp
	glGetDoublev GL_MODELVIEW_MATRIX,ortho_mv
	glGetDoublev GL_PROJECTION_MATRIX,ortho_pj
	
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	glMatrixMode GL_PROJECTION
	glLoadIdentity
	glOrtho 0,vp[2],vp[3],0,-1,1

	glDisable GL_CULL_FACE
	glDisable GL_ALPHA_TEST	
	glDisable GL_DEPTH_TEST
End Function

Function EndOrtho()
	glMatrixMode GL_PROJECTION
	glLoadMatrixd ortho_pj
	glMatrixMode GL_MODELVIEW
	glLoadMatrixd ortho_mv
	
	glPopAttrib
End Function


I tried this sample and after compiling prg show that FBO isn't suported, but it's strange because i have NV 8800 GTX. What is problem?