Mixing Max2D and OpenGL

BlitzMax Forums/OpenGL Module/Mixing Max2D and OpenGL

ozak(Posted 2005) [#1]
Hi. I was wondering if it's still possible to mix Max2D and OpenGL. Would be nice to use Max2D for GUI stuff and then plain GL for 3D.


ghislain(Posted 2005) [#2]
it can be done. but mark didn't recommand it some time ago. because it might interfere with the max2d internals. be ready for some awkward effects...
i think you will be most succesfull if you do all your 2dmax stuff first followed by the 3d stuff [or vv]..

ghislain


ozak(Posted 2005) [#3]
Right. I'll give it ago. Figures you should'nt mix Max2D and GL (dangerous coctail or something ;)


ozak(Posted 2005) [#4]
Hmm. I tried multiple solutions, but I can't seem to mix Max2D and GL. If I create the screen by GL context, Max2D crashes with a null pointer exception and If I do Graphics and then GL commands, they just get ignored.

Anyone?

EDIT: I'm a bum. Forgot BMax defaults to DX on windooze. Set GL driver and all is fine :) Still some issues though :)


ozak(Posted 2005) [#5]
Quick hack of Nehe Tutorial 5.
I got a yellow max2d box on screen and a rotating triangle.
Problems:

- DrawText removes all OpenGL stuff from screen.
- I can't clear the color buffer of use Cls as either Max2D or GL stuff disappears.

I would appreciate any help towards a rock solid Max2D/OpenGL implementation :)



Framework BRL.GLMax2D


SetGraphicsDriver GLMax2DDriver()
Graphics 640,480,0



Global rtri:Float									'Angle For The Triangle ( New )

	

While Not KeyHit( KEY_ESCAPE )
	
	SetColor(255,255,0)

	DrawRect(0,0,640,100)	
	SetColor(0,0,255)
	
	'DrawText("Hello GL!",0,0) '<- This removes all OpenGL stuff on screen
	
	' Triangle background not cleared, as I can't clear the color buffer or use CLS
	DoGl()

	Flip()

Wend

Function DoGL()

	
	glPushMatrix
	glenable GL_DEPTH_TEST								'Enables Depth Testing

	glMatrixMode GL_PROJECTION							'Select The Projection Matrix
	glLoadIdentity										'Reset The Projection Matrix

	glFrustum -0.1, 0.1,-0.1, 0.1, 0.1, 100.0				'Setup The Projection Matrix Frustum

	glMatrixMode GL_MODELVIEW							'Select The ModelView Matrix
	glLoadIdentity										'Reset The ModelView Matrix

	glClear GL_DEPTH_BUFFER_BIT		'Clear The Screen And The Depth Buffer
	
	glLoadIdentity									'Reset The ModelView Matrix
	glTranslatef -1.5,0.0,-6.0						'Move Left 1.5 Units And Into The Screen 6.0

	glRotatef rtri,1.0,1.0,0.0						'Rotate The Triangle On The Y axis ( New )
	glBegin GL_TRIANGLES							'Drawing Using Triangles

		glColor3f 1.0,0.0,0.0						'Red
		glVertex3f 0.0, 1.0, 0.0						'Top Of Triangle (Front)
		glColor3f 0.0,1.0,0.0						'Green
		glVertex3f -1.0,-1.0, 1.0					'Left Of Triangle (Front)
		glColor3f 0.0,0.0,1.0						'Blue
		glVertex3f 1.0,-1.0, 1.0						'Right Of Triangle (Front)
	
		glColor3f 1.0,0.0,0.0						'Red
		glVertex3f 0.0, 1.0, 0.0						'Top Of Triangle (Right)
		glColor3f 0.0,0.0,1.0						'Blue
		glVertex3f 1.0,-1.0, 1.0						'Left Of Triangle (Right)
		glColor3f 0.0,1.0,0.0						'Green
		glVertex3f 1.0,-1.0, -1.0					'Right Of Triangle (Right)

		glColor3f 1.0,0.0,0.0						'Red
		glVertex3f 0.0, 1.0, 0.0						'Top Of Triangle (Back)
		glColor3f 0.0,1.0,0.0						'Green
		glVertex3f 1.0,-1.0, -1.0					'Left Of Triangle (Back)
		glColor3f 0.0,0.0,1.0						'Blue
		glVertex3f -1.0,-1.0, -1.0					'Right Of Triangle (Back)

		glColor3f 1.0,0.0,0.0						'Red
		glVertex3f 0.0, 1.0, 0.0						'Top Of Triangle (Left)
		glColor3f 0.0,0.0,1.0						'Blue
		glVertex3f -1.0,-1.0,-1.0					'Left Of Triangle (Left)
		glColor3f 0.0,1.0,0.0						'Green
		glVertex3f -1.0,-1.0, 1.0					'Right Of Triangle (Left)

	glEnd										'Finished Drawing The Pyramid
	

	rtri:+1
	glPopMatrix
	
	
End Function



EOF(Posted 2005) [#6]
This may be of interest to you. From Marks latest worklog:

Besides the GUI, other notable module efforts include the 'unification' of some aspects of the graphics stuff. Commands like Graphics/EndGraphics/GraphicsModes/Flip are now common to a variety of drivers, eg: GL, Max2D, D3D7, D3D9. This means BlitzGL will be going, as you can now get exactly the same functionality from the graphics system, eg:

SetGraphicsDriver GLGraphicsDriver()
Graphics 640,480    'now in 'raw' GL mode!
While Not KeyHit( KEY_ESCAPE )
   glClear GL_SOMETHING_BIT
   Flip
Wend


In fact, there is now a 'GLGraphics' command that does the first 2 lines for you...

I wonder if that means each graphics driver now includes its own set of commands such as DrawText, DrawRect, Cls. Thereby avoiding any mixing of modes(?)


ozak(Posted 2005) [#7]
Sounds good :)


Ibmurai(Posted 2005) [#8]
Can't wait!