PDA

View Full Version : Depth Buffering



SpaceCadet
04-21-2000, 08:44 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif. I'll post my code if that will help, but it's really bad http://www.opengl.org/discussion_boards/ubb/smile.gif.

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

MikeC
04-22-2000, 05:50 AM
Weird. You aren't doing something silly like applying your viewpoint rotations to the projection matrix, are you? That might explain it.

Antoche
04-22-2000, 01:36 PM
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.

SpaceCadet
04-22-2000, 05:04 PM
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.

MikeC
04-22-2000, 06:10 PM
There should be a glMatrixMode(GL_MODELVIEW) somewhere before you call glLookAt. If there isn't, I'd say that's your problem.

JSoffer
04-22-2000, 10:33 PM
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?

Antoche
04-23-2000, 12:35 PM
>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.

SpaceCadet
04-23-2000, 01:51 PM
it was my mistake I use glMatrixMode(GL_MODELVIEW)

john
04-26-2000, 07:05 PM
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