My test app displays a unit cube and allows me to orient it with pitch and yaw controls. In wireframe mode, the viewing and perspective projection are demonstrated to be correct.
Chaos ensues when I enable lighting and the depth test.
Display works correctly only if I enable back-face culling. If I do not cull back faces, then the back faces of the cube get drawn over the top of the front faces. The back facing geometry seems to have its depth calculated incorrectly, so it clobbers front faces that are actually closer to my view point.
I understand why you cull backfaces to improve efficiency, but I didn’t think you had to cull them to achieve correctness.
Yes, I understand about GL_CW vs GL_CCW faces. That’s not the problem. When I DO cull backfaces, it DOES display the front faces correctly.
I bet you have forgotten to enable depth testing and set the needed depth test.So do this in the initialization of your app and every thing should be displayed as you want it to be :
No, that’s not it. I do enable the depth test and have tried both GL_LESS and GL_LEQUAL with no luck.
Have you requested a pixelformat with a cDepthBits > 0?
Otherwise a screenshot would help.
Push your near plane out. Google for depth fighing and/or look at the FAQ on this site.
PanzerSchreck was correct. My pixel format lacked a depth buffer.
It’s a Cocoa app for Mac OS X. NSOpenGLView lacks a depth buffer by default. You have to give it one by overriding the initializer method.
The apparant success with back faces culled was a red herring. When you render a single convex polyhedron, back face removal is the only hidden surface technique you need. So it looked great even without a depth buffer.
I never saw a more beautiful pitchin’ and yawin’ gray unit cube in my life!