Archived

This topic is now archived and is closed to further replies.

explain me the depth test

This topic is 5016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi im kinda new to openGL. so can anyone please explain me what exactly the depth test does. at the moment i use this: glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); but when i zoom very close to my objects some parts at the far-end get culled away. www.embege.com

Share this post


Link to post
Share on other sites
The depth buffer holds values ranging from 0 to 1,
the depth test makes sure only fragments with a certain depth value are saved in the color buffer, if that certain depth value is glDepthFunc(GL_LESS); than the already exsisting value then the color buffer is changed, and the depth value in that place is changed to match the new value. It is used to make sure no matter what order you draw the world it is drawn correctly in repsect to depth.

glClearDepth sets the values that the depth buffer is filled with on a depth buffer clear

glDepthFunc tells what situation to allow fragments to pass the test under.

glDepthMask allows you turn on/off updating the depth buffer, usefull for using transparent particals.

I hope that helps, I might have messed up a little bit, but I guess thats the basic gist of it.



"I seek knowledge and to help those who also seek it"

Share this post


Link to post
Share on other sites
I think this is how it works!

Whenever you draw a triangle in OGL, it fills out the xy plane on the screen, with colors/textures ... , but, the z (into the screen) of every pixle is drawen to the depth buffer/Z buffer!
Now, when you draw another pixle (in a triangle) , it only draws the pixle, if its (in your case) LESS then the last pixle drawen there, in practical language, things behind other things will not be drawen.

The cliping of your triangles, should have something with the near and far plane, since the zbuffer only got a fixed resolution, 16 bit i think, you have to trim your far and near plane, to be as close to each other as possible, now in a great outdoor sceene, they wont be close, but you should try, because with a lower range in the z buffer, you get a more accurate z dist, and lesser z-fighting... (two objects are so close in the z plane, that OGL cant calc witch is the closest, so they flicker.)

i hope this answered your question!

Share this post


Link to post
Share on other sites
the z-buffer can be a size you request, it used to be stuck at 16bit however pretty much any card around these days from the TNT upwards can do a 24bit z-buffer and my 9800xt says it can do a 32bit z-buffer

The ''flickering'' problem with the depth buffer is all todo with how it works, there is more resolution close to the near plan and it drops off to a log scale, so to get more presision at the far plane you generaly have to move the near plane into the screen a bit, a small change there gives you more depth to work with.

Share this post


Link to post
Share on other sites