PDA

View Full Version : depth test issue - urgent



dalemac
01-26-2011, 04:40 PM
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?

Thanks,

Dale

carsten neumann
01-26-2011, 04:54 PM
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.

dalemac
01-26-2011, 04:57 PM
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?

Thanks,

Dale

dalemac
01-26-2011, 05:14 PM
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 :(

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

Anyway, thanks for asuring me where the problem was!

Dale

mobeen
01-26-2011, 06:49 PM
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) {
if(newH==0)
return;
glViewport(0,0,newW, newH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,float(newW)/newH,1,100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}