• 12
• 27
• 9
• 20
• 33

problem with glOrtho

This topic is 4778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
Quote:
 Original post by jake_Ghostive 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 advancedJake

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()

Share on other sites
well i am using it for a hud, do u no how to turn off glOrtho after i draw the hud?

Share on other sites
Quote:
 Original post by jake_Ghostwell 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

Share on other sites
Quote:
 Original post by jake_Ghostwell 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

Share on other sites
Heh, whoops, Kalidor's right. You need to set the matrix to GL_PROJECTION or you'll get some interesting results, indeed.

Share on other sites
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;								}

Share on other sites
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);

Share on other sites
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.

Share on other sites
Quote:
 Original post by jake_Ghoststill 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.