Rendering a (cal3D) 3D mesh in glOrtho: faces get front/back messed up. FIXED

Started by
2 comments, last by owl 15 years, 10 months ago
Hi, I'm trying to render a 3D mesh within an orthographic projection and the mesh faces are not being rendered in the proper way, the ones behind appear mixed/screwed up with the ones on the front. This gets more obvious when you rotate the mesh. With or without enabling GL_DEPTH_TEST I'm getting the same result. The mesh is being rendered as a vertex array with glDrawElements (as they do in the CAL3D examples) I'm setting glOrtho as usual. Light0 is on and set up, blending is on, texturing is off. I set it like this:

glViewport(0, w, h, 0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1, 0, 1, -100000.0, 100000.0);
    glMatrixMode(GL_MODELVIEW);
If I comment the ortho part and I render this mesh with a perspective projection it looks perfect. The problem is with the orthographic one. I don't have the exact source code with me right now. I'll try to bring it on later. Thanks in advance. [Edited by - owl on June 18, 2008 9:40:10 AM]
[size="2"]I like the Walrus best.
Advertisement
hi owl,

your enormous depth range (-100000..100000) kills the precision of the depth buffer. try to reduce the depth range to the real extents of your scene...

regards
zimerman
In addition to zimerman's answer: If you compare your set-up using glOrtho with your set-up using glFrustum, then you'll see a significant difference in the value of zNear. You've set zNear to -100000.0 for glOrtho, i.e. a value far behind the camera. Then, of course, scene stuff located behind the camera becomes visible, too. It is questionable whether this is really "as usual" for glOrtho. However, for glFrustum you use a relatively small zNear in front of the camera, didn't you? So set zNear for glOrtho to, e.g., 0 and you'll benefit from a doubled z-buffer resolution as well. Then think about the 100000 for zFar, as zimerman has suggested.
Quote:Original post by zimerman
hi owl,

your enormous depth range (-100000..100000) kills the precision of the depth buffer. try to reduce the depth range to the real extents of your scene...

regards
zimerman


That was it. Thank you very much.
[size="2"]I like the Walrus best.

This topic is closed to new replies.

Advertisement