Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Ortho Trouble

This topic is 3675 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

Hi, This should be a pretty basic question. Soon after I began OpenGL a few years ago, I realized that, among other things, I didn't know how to do Ortho projections. It never really became important, so I didn't really worry about it. I decided it would be good to know. Currently, my view is made using the latter function in this code snippet.
def viewport2D(rect,near,far):
    glViewport(*rect)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity() 
    glOrtho(rect[0],rect[2],rect[1],rect[3],near,far)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
def viewport3D(rect,angle,near,far):
    glViewport(*rect)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity() 
    gluPerspective(angle,float(rect[2])/float(rect[3]),near,far)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
The former, which I use in exactly the same way, is my assumption of how to do Ortho. Unfortunately, I see nothing when using it on several demos. Sorry, just don't see anything--only the fill color, black. Any idea why this might be? Thanks, Ian

Share this post


Link to post
Share on other sites
Advertisement
glOrtho(rect[0],rect[2],rect[1],rect[3],near,far)

My gut feeling is you have this set wrong or you have rendered your objects in front or behind the near/far planes. Make sure you have a near far plane e.g. -100,100 to start with and translate to say 10 or something.

Share this post


Link to post
Share on other sites
replacing
def viewport2D(rect,near,far):
glViewport(*rect)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(rect[0],rect[2],rect[1],rect[3],near,far)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
with
def viewport2D(rect,near,far):
glViewport(*rect)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45,float(rect[2])/float(rect[3]),near,far)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
Lets the code work normally; otherwise, I don't see anything.
-G

Share this post


Link to post
Share on other sites
Update:

I just realized, I can see stuff, but now the objects are in screen coordinates. So the cube at (0,0,0) is now 1 pixel big and at the bottom left corner of the screen.

I wanted the Ortho to make the perspective parallel, like the way these objects are seen: http://leannekroll.files.wordpress.com/2008/06/iso.gif.

In short, I want to see the 3D objects just as they were seen in perspective, but in and isometric projection. Is there a nice way to do that?

-G

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!