Rotate view?

BlitzMax Forums/OpenGL Module/Rotate view?

Who was John Galt?(Posted 2005) [#1]
I have some text scrolling up the screen but I would like to give it the starwars intro effect. Can I rotate the camera view to get perspective whilst still using Max2D for the majority of the code? Any help appreciated.


Haramanai(Posted 2005) [#2]
I think that you cannot use Max2D abd rotate the angle of the view. Because Max2D uses (I think) strictly GluOrtho2D or glOrtho.


ImaginaryHuman(Posted 2005) [#3]
I don't see any reason why you can't call glOrtho2D or whatever any number of times in your code, ie before you render stuff, to give you a perspective projection.


Who was John Galt?(Posted 2005) [#4]
Correct, Daniel. Cracked it last nite. You can reset the projection in your code.


ImaginaryHuman(Posted 2005) [#5]
It's pretty handy too - basically you are moving the camera and it lets you zoom, rotate and fly your game screen around in three dimensions pretty easily.


Who was John Galt?(Posted 2005) [#6]
Yeah I like it but I'm slow getting to grips with OGL. It works but I don't know if I'm doing things 'the right way'


Diordna(Posted 2005) [#7]
So, how about posting your code? Because this would be totally sweet to see used in the middle of a game :)


Who was John Galt?(Posted 2005) [#8]
graphics 800,600,32
starfont=loadimagefont("Jedi Normal")
'glPushmatrix()
SetImageFont starfont

Const text_row_h=70

'MY STUFF HERE


fin=0



ystart#=450.00

SetBlend ALPHABLEND
ncount=0
ndelay=1

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(20.0,-8.0/6.0,1.0,100000.0)
glrotatef(180.0,0,0,1)
'glrotatef (180.0,0.0,0.0,1.0)

glEnable(GL_FOG)
Local fcols:Float[]=[0.0,0.0,0.0,0.0]
Local colptr:Float Ptr=VarPtr fcols[0]


glFogfv(GL_FOG_COLOUR,colptr)
glFogf(GL_FOG_START,500)
glFogf(GL_FOG_END,1000)
glFogi(GL_FOG_MODE,GL_LINEAR)

xpos=-108
angg#=80.0
dist=-836.0
scaley#=1.29599917
scalex#=0.113999963

Cls
Flip

Repeat

	Cls
	
	glMatrixMode(GL_MODELVIEW)
	glLoadidentity()
	SetOrigin xpos,ystart
	glTranslatef(0,0,dist)
	glrotatef(angg,1,0,0)
	SetScale scalex,scaley
	
		SetColor Rand(0,255),Rand(0,255),Rand(0,255)
		DrawText "      ***********************************",0.0,text_row_h
		DrawText "      *       your text here!!                  *",0.0,text_row_h*2
		DrawText "      **********************************",0.0,text_row_h*3
		DrawText "      *            **************                *",0.0,text_row_h*4
		DrawText "      *************04/05*************",0.0,text_row_h*5
		
	EndIf
	
	ncount:+1
	If ncount>ndelay Then ncount=0
	If ncount=0 Then ystart:-1
	
	
	Flip
Until KeyHit(KEY_ESCAPE) Or ystart<-2000.0

glMatrixMode GL_PROJECTION
glLoadidentity()
glOrtho 0,800,600,0,-1,1

SetScale(1,1)
SetColor 255,255,255
SetAlpha 1.0

glMatrixMode GL_MODELVIEW
glLoadIdentity
SetOrigin 0,0

glDisable(GL_FOG)
'glPopmatrix()
Cls
Flip



Here you go - I've tried to make a couple of mods so you can run it straight off the bat - untested - you'll need to download a font called 'Jedi Normal' to
see it as intended - this is on a website called "2200 free fonts" - available in Mac or PC format. Make sure the font filename is correct in the code above.


Diordna(Posted 2005) [#9]
compile errors!

"endif" without "if
missing parameter "size" in line 2

had to go at that point, hope that helps


Who was John Galt?(Posted 2005) [#10]
Graphics 800,600,32
starfont=LoadImageFont("Jedi Normal",48)
'glPushmatrix()
SetImageFont starfont

Const text_row_h=70

'MY STUFF HERE


fin=0



ystart#=450.00

SetBlend ALPHABLEND
ncount=0
ndelay=1

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(20.0,-8.0/6.0,1.0,100000.0)
glrotatef(180.0,0,0,1)
'glrotatef (180.0,0.0,0.0,1.0)

glEnable(GL_FOG)
Local fcols:Float[]=[0.0,0.0,0.0,0.0]
Local colptr:Float Ptr=VarPtr fcols[0]


glFogfv(GL_FOG_COLOUR,colptr)
glFogf(GL_FOG_START,500)
glFogf(GL_FOG_END,1000)
glFogi(GL_FOG_MODE,GL_LINEAR)

xpos=-108
angg#=80.0
dist=-836.0
scaley#=1.29599917
scalex#=0.113999963

Cls
Flip

Repeat

        Cls
        
        glMatrixMode(GL_MODELVIEW)
        glLoadidentity()
        SetOrigin xpos,ystart
        glTranslatef(0,0,dist)
        glrotatef(angg,1,0,0)
        SetScale scalex,scaley
        
        SetColor Rand(0,255),Rand(0,255),Rand(0,255)
        DrawText "      ***********************************",0.0,text_row_h
        DrawText "      *       your text here!!                  *",0.0,text_row_h*2
        DrawText "      **********************************",0.0,text_row_h*3
        DrawText "      *            **************                *",0.0,text_row_h*4
        DrawText "      *************04/05*************",0.0,text_row_h*5
	DrawText "BLAH BLAH etc ",0,text_row_h*6
	DrawText "*                                                                                 *",0,text_row_h*7
	DrawText "*                                                                                 *",0,text_row_h*8 
	DrawText "*                                                                                 *",0,text_row_h*9	
	
	       
        ncount:+1
        If ncount>ndelay Then ncount=0
        If ncount=0 Then ystart:-1
        
        
        Flip
Until KeyHit(KEY_ESCAPE) Or ystart<-2000.0

glMatrixMode GL_PROJECTION
glLoadidentity()
glOrtho 0,800,600,0,-1,1

SetScale(1,1)
SetColor 255,255,255
SetAlpha 1.0

glMatrixMode GL_MODELVIEW
glLoadIdentity
SetOrigin 0,0

glDisable(GL_FOG)
'glPopmatrix()
Cls
Flip



OK- snapped out of the bout of laziness. This is tested. Just need the font in the same dir.


Diordna(Posted 2005) [#11]
Thanks. I've used this for some awesome in-game transitions...fade out and spin, then spin back in real fast :)

One more thing - how do I set the origin of rotation? opengl noob speaking here. Thanks.


Who was John Galt?(Posted 2005) [#12]
Erm - I'm an OGL noob, too. Did most of this by 'fiddling about'. Look at the GLtranslatef() and the GLrotatef() in the main loop - these tell OpenGL to translate so far along the x,y,z axes [GLtranslate (distx,disty,distz)] then from that centre rotate n degrees about vector 'A' [GLrotatef(angle,Ax,Ay,Az)] - before drawing the text - try fiddling with these.


Diordna(Posted 2005) [#13]
Yes, that's all well and good, but then how do I move the camera back before rendering?


Who was John Galt?(Posted 2005) [#14]
You don't - you move the scene forward using a GLtranslatef().