Jump to content
  • Advertisement
Sign in to follow this  
jake_Ghost

problem with glOrtho

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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()

Share this post


Link to post
Share on other sites
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 rendering

glPushMatrix();
glLoadIdentity();
glOrtho( ... );

// Do your ortho stuff here

glPopMatrix();

// Back to Perspectice-Correct stuff

Share this post


Link to post
Share on other sites
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 this
since the hud will be drawn last. If you do need to save the modelview
matrix, 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 earlier

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);






EDIT: Beaten, damn comment was too long :P

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 UI

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glEnable(GL_DEPTH_TEST);

Share this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!