Depth Buffering

Ok, here is the situation. I have a height map rendered as a quad strip. If I travel at ground level in the positive z-axis depth buffering works properly. However when I turn around and travel in the negative direction on the z-axis it doesn’t work. I can see things that shouldn’t be rendered. When I travel along the x-axis in either the positive or negative direction I have half of the screen with depth buffering working and the other half not working. Anyway I’m not that experienced coding in OpenGL, and I think I’m just doing something really stupid . I’ll post my code if that will help, but it’s really bad .

[This message has been edited by SpaceCadet (edited 04-21-2000).]

Weird. You aren’t doing something silly like applying your viewpoint rotations to the projection matrix, are you? That might explain it.

Well, I think the problem seems to be that you just don’t enable the depth test, so polygons that are drawn first are hided by last. Just type glEnable(GL_DEPTH_TEST); after the initialization of OpenGL.

I’m calling glEnable(GL_DEPTH_TEST). I may be messing with the projection matrix I’m not really sure. Each time I render the scene I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(…) to set up the veiwing.

There should be a glMatrixMode(GL_MODELVIEW) somewhere before you call glLookAt. If there isn’t, I’d say that’s your problem.

Originally posted by SpaceCadet:
I’m calling glEnable(GL_DEPTH_TEST). I may be messing with the projection matrix I’m not really sure. Each time I render the scene I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(…) to set up the veiwing.

Maybe I’m wrong, but calling Load Identity() before setting your glMatrixMode isn’t going to screw things really bad?

>I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(…)
It’s not the right way. Instead you must call glMatrixMode(GL_MODELVIEW); glLoadIdentity(); and gluLookAt(…)
And at the beginning of the program after initialization, call glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(…). Look at tutorials.

it was my mistake I use glMatrixMode(GL_MODELVIEW)

Hmm, although you’re right in that gluLookAt should apply to the modelview matrix, when you think about how the maths all works out, it shouldn’t really mater. I mean, the projection eqn is:

v’=Pv

right? With a modelview matrix it’s

v’=PMv

so it doesn’t REALLY matter if it’s

v’=(PM)Iv

or

v’=P(IM)v

where the first case is postmultiplying the projection matrix with the lookat, and in the second case, postmultiplying the identiy modelview matrix with the lookat.

cheers
John