Overlapping Rectangles

Okay, I’m doing a project where I need three rectangles, each on a different axis, that I can spin around and view. The problem is that instead of displaying the way they would in real life, the one that’s drawn last just covers the other two. I guess the problem is with depth. This is probably something simple I’m missing but it really has me stumped.

Do you use pixel format which contains the depth buffer? If you are using GLUT, you need to ask for it using the GLUT_DEPTH flag. Is depth test (GL_DEPTH_TEST) enabled? It is disabled by default.

When I try to glEnable(GLUT_DEPTH_TEST) the rectangles don’t show up at all. The window is just filled with my clear color.

I assume that you meant glEnable(GL_DEPTH_TEST), there is no such GLUT constant. Did you clear the depth buffer at start of the frame together with the color buffer?

Oh and a classic caveat: If you’re using orthographic projection you must use a reverse depth test that is, fragments with greater z pass.

Really ? I have seen quite some caveats, but first time I hear about this one :slight_smile:

Heh, OK, maybe not classic but to me it wasn’t obvious in the first place.