depth test issue - urgent

Hi everyone,

i have finished my game for my assignment (which i have to hand in tomorrow at 4pm uk time), but i have ran into an issue with depth testing. i am sure i am using it correctly, (enabling, clearing the buffer, and init with depth test).

basically, it is not drawing objects correctly, and is flashing surface when using the camera etc.

i have tried using LEQUAL etc, which is the closest, but still isnt working properly.

i have read into an issue with gluperspective messing this up if the zNear isnt set above zero, but im not using gluPerspective, im using gluLookat. I have added gluPerspective but it isnt making any difference.

Is there anything else which may mess with depth testing?



but im not using gluPerspective, im using gluLookat.

those are for different purposes, one is to set up the projection matrix the other the ‘viewing part’ of the modelview matrix.
One common reason for incorrect/flickering depth testing is a too small near value or an excessive ratio between far and near (e.g. near = 0.001 far = 100000), the depth buffer does not have enough resolution for such a setup. Increasing near in these cases has a much more pronounced effect than reducing far.

Thanks for the quick reply.

So how should i be setting up gluPerspective? before or after my gluLookat call? what would be a good starting point for setting up gluPerspective?



Ok, i found the culprit…

seems that in my resize function the zNear was set to .0.

And to think i have been starting at this for the last 2 hours is shameful :frowning:

to be fair though, i have had very little sleep because of this assignment, and i still have some modeling to complete for tomorrow :frowning:

Anyway, thanks for asuring me where the problem was!


FYR usually, we setup the projection matrix once and the preferred place to keep it is in the resize handler and also set the modelview matrix when we leave it.

void OnResize(int newW, int newH) {
   glViewport(0,0,newW, newH);