Ortho Trouble

Started by
3 comments, last by Geometrian 15 years, 7 months ago
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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.
Even with the near/far planes set to large numbers, I don't see anything. If the context of the code is important, here is a link to the source: http://www.geometrian.com/Programs/OpenGL Library 1.4.zip The last test tests ortho. I don't see anything when I run it.
Thanks,
G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement