explain me the depth test

Started by
4 comments, last by ehmdjii 20 years ago
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
Advertisement
anyone?
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"
"I seek knowledge and to help those who also seek it"
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!
-Anders-Oredsson-Norway-
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.
Doesn''t anyone read the Forum FAQ anymore?

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement