max2d on MaxGui canvas - resize trouble

BlitzMax Forums/MiniB3D Module/max2d on MaxGui canvas - resize trouble

Difference(Posted 2007) [#1]
Thanks for a great v.0.45 release.

I'm trying to hack together a working example of max2d on a resizable canvas with minib3d.

I can't seem to make max2D resize to fit the canvas.
I was thinking SetViewport 0,0, TGlobal.width, TGlobal.height in the EVENT_WINDOWSIZE event should do it, but it doesn't seem to work.

Can somebody help?

(resize window larger and hit spacebar to see clipping of fireworks)




klepto2(Posted 2007) [#2]
Sorry for the delay: here is a solution for your problem:

Replace the BeginMax2D() code block in your code with this:

		
	BeginMax2D() ' MiniB3D function
	glViewport(0,0,TGlobal.Width,TGlobal.Height)
		glScissor(0,0,TGlobal.Width,TGlobal.Height)



Leon Drake(Posted 2007) [#3]
ah looks like i may need to do that as well.


Leon Drake(Posted 2007) [#4]
LOL i just tried it without BeginMax2D and it draws the 2d in 3d.


Leon Drake(Posted 2007) [#5]
just tested this, it does align the 2d however its scaled instead of repositioned, so when i try to draw something like a wireframe its offcentered.


Difference(Posted 2007) [#6]
Thanks for looking into this.

Yes, get what Leon gets too.
F.ex. the text get stretched with the example above.


klepto2(Posted 2007) [#7]
Yeah, getting this also with the new minib3d 045, will have a closer look tomorrow.


klepto2(Posted 2007) [#8]
Function BeginMax2D()

Local x,y,w,h
		GetViewport(x,y,w,h)
		
		glDisable(GL_LIGHTING)
		glDisable(GL_DEPTH_TEST)
		glDisable(GL_SCISSOR_TEST)
		glDisable(GL_FOG)
		glDisable(GL_CULL_FACE)

		glMatrixMode GL_TEXTURE
		glLoadIdentity
		
		glMatrixMode GL_PROJECTION
		glLoadIdentity
		glOrtho 0,GraphicsWidth(),GraphicsHeight(),0,-1,1
		
		glMatrixMode GL_MODELVIEW
		glLoadIdentity
		
		SetViewport x,y,w,h
		
		
		Local MaxTex:Int 
		glGetIntegerv(GL_MAX_TEXTURE_UNITS, Varptr(MaxTex))

		
		For Local Layer = 0 Until MaxTex
			glActiveTexture(GL_TEXTURE0+Layer)
					
			glDisable(GL_TEXTURE_CUBE_MAP)
			glDisable(GL_TEXTURE_GEN_S)
			glDisable(GL_TEXTURE_GEN_T)
			glDisable(GL_TEXTURE_GEN_R)
	
			glDisable(GL_TEXTURE_2D)
		Next
		
		glActiveTexture(GL_TEXTURE0)
		
		'DrawRect - 10 , - 10 , 5 , 5
		
		glViewport(0,0,TGlobal.Width,TGlobal.Height)
		glScissor(0,0,TGlobal.Width,TGlobal.Height)
		

End Function

Function EndMax2D()

		glDisable(GL_TEXTURE_CUBE_MAP)
		glDisable(GL_TEXTURE_GEN_S)
		glDisable(GL_TEXTURE_GEN_T)
		glDisable(GL_TEXTURE_GEN_R)
	
		glDisable(GL_TEXTURE_2D)

		TGlobal.EnableStates()

End Function


Replace these Functions with the original ones or just insert them in your App to override the original ones. This should work.


Difference(Posted 2007) [#9]
YES! Those work. Thanks!


Leon Drake(Posted 2007) [#10]
awesome