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

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

Recommended Posts

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);
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]

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

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

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

That was it. Thank you very much.