Depth Buffering Question

Hi Gang,
Need some clarification on how Depth Buffering works in the case where the Z values for two objects being drawn are the same value. Does the object being drawn econd go on top of the object drawn first? When I tried to test this situation, it looked like the two objects “blended” together, with the second object intersecting the first object in some spots. Is there w way that I can get the second object to lay directly on top of the first (without using a offset for the Z axis)?

For instance my first object it a Sphere (actually a globe) and I am trying to draw a lat/lon grid on top of the globe, but I don't want any space between the globe and the lat/lon grid.  

so this is what I do (in theory - not real code!)

glEnable(GL_DEPTH_TEST);
gluSphere(globe_, globeRadius, 48, 48);

// Draw Lat/Lon takes in a radius value
drawLatLon(globeRadius);

Like I said earlier - keeping the radius of both objects the same seems to make the objects blend together, with the lat/lon grid intersecting through the globe in some areas. 

if I do the following, I solve the intersecting problem, but the lat/lon grid seems to "float" above the globe (i.e. you can see a space between the grid and the globe).

glEnable(GL_DEPTH_TEST); gluSphere(globe_, globeRadius, 48, 48);

// Draw Lat/Lon takes in a radius value
drawLatLon(globeRadius + 0.1);

Any ideas? Comments?

Thanks
Roach

Are you familar with glDepthFunc?

[This message has been edited by Coconut (edited 01-06-2003).]

Yes,
In fact I have tried using all options for glDepthFunc, I eather got the full lat/lon grid to show (including the back part of the grid, which should have been culled) using a GL_GREATER/GL_GEQUAL or I got the blending issue by using a GL_LESS/GL_LEQUAL.

Thanks
Roack

glPolgonOffset is designed to solve such problems…

If two triangles don’t share the same vertices, even mathematically coplanar polygons will not have identical depth buffer values due to aliasing artifacts inherent to finite-precision math. So you typically have to use polygon offset or make sure you duplicate the triangles. Another trick that usually works is to use slightly different depth ranges… for example 0 to 1 - epsilon for the stuff that should be in front, and epsilon to 1 for stuff that should be in back. Epsilon should be a small integer multiple of 2 ^ (- num of depth bits).