problem with glOrtho

Started by
18 comments, last by Mercury 19 years, 2 months ago
ive got my glOrtho projection working some what ok, but the rest of teh screen is all screwed up now. When i draw a simple box with a texture on it, it gets all deformed or the depth stuff is all messed up. I dont no how to show a screen shot so unfortunatly i cant show u what i mean. Could someone tell me how to fix this problem? thx in advanced Jake
Advertisement
Quote:Original post by jake_Ghost
ive got my glOrtho projection working some what ok, but the rest of teh screen is all screwed up now. When i draw a simple box with a texture on it, it gets all deformed or the depth stuff is all messed up. I dont no how to show a screen shot so unfortunatly i cant show u what i mean. Could someone tell me how to fix this problem?

thx in advanced
Jake

What are you doing using 3d stuff with an orthographic projection matrix? What you want is a perspective correct projection matrix. Orthographics are for things like grids in level editors, 2d text overlays, etc. They're not used for doing things like 3d simulation.
Take a look at gluPerspective()
well i am using it for a hud, do u no how to turn off glOrtho after i draw the hud?
Quote:Original post by jake_Ghost
well i am using it for a hud, do u no how to turn off glOrtho after i draw the hud?

Use matrix stacks.

// Normal renderingglPushMatrix();glLoadIdentity();glOrtho( ... );// Do your ortho stuff hereglPopMatrix();// Back to Perspectice-Correct stuff
Quote:Original post by jake_Ghost
well i am using it for a hud, do u no how to turn off glOrtho after i draw the hud?


You do something like this...
//All rendering of world, objects, etc.glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glOrtho(...);glMatrixMode(GL_MODELVIEW);glLoadIdentity();/*Assuming you will not need the current modelview matrix anymore after thissince the hud will be drawn last.  If you do need to save the modelviewmatrix, just push it before glLoadIdentity() and then pop it later*///...Do HUD/whatever rendering here...//Here you would pop the modelview matrix if you pushed it earlierglMatrixMode(GL_PROJECTION);glPopMatrix();glMatrixMode(GL_MODELVIEW);



EDIT: Beaten, damn comment was too long :P
Heh, whoops, Kalidor's right. You need to set the matrix to GL_PROJECTION or you'll get some interesting results, indeed.
hmmm i cant get it to work heres the code

int GLDraw :: DrawUI(GLvoid){	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glPushMatrix();		glOrtho(0,1024,0,768,-1.0f,1.0f);		glMatrixMode(GL_MODELVIEW);		glLoadIdentity();		glDisable(GL_DEPTH_TEST);                // draws UI		glMatrixMode(GL_PROJECTION);		glLoadIdentity();	glPopMatrix();	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glEnable(GL_DEPTH_TEST);	return TRUE;								}
You're clearing your matrix, then storing it in the stack.... You want to store it (glPushMatrix), then clear it (glLoadIdentity).
And you don't need to load identity before popping the matrix.

EDIT:
Here:
glDisable(GL_DEPTH_TEST);glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glOrtho(0,1024,0,768,-1.0f,1.0f);glMatrixMode( GL_MODELVIEW );glPushMatrix();glLoadIdentity();// Draw UIglMatrixMode(GL_MODELVIEW);glPopMatrix();glMatrixMode(GL_PROJECTION);glPopMatrix();glEnable(GL_DEPTH_TEST);
still dont work for some reason, it looks like the z range is to small for the object so its squishing it but still losing parts of the image.
Quote:Original post by jake_Ghost
still dont work for some reason, it looks like the z range is to small for the object so its squishing it but still losing parts of the image.


Yeah, with ortho the way we said with -1 near and 1 far plane values, that would probably not be enough for a 3d object, so if you are rendering 3d objects in an orthographic view you need to increase the far clipping plane value.

This topic is closed to new replies.

Advertisement