PDA

View Full Version : Depth Buffering Question!



Roach
01-06-2003, 09:56 AM
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 second 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

Sektor
01-06-2003, 10:24 AM
What you're talking about is called z-fighting.
You could try using 0.01 (or a value even lower instead of that 0.1).

Halcyon
01-06-2003, 12:18 PM
I think you are looking for the glPolygonOffset() procedure. Check it out on page 251 of the Red Book (http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/) . It is the very end of the 6th chapter. There is a section call "polygon offset". Use the blue arrow to the left of Chapter 6 to expand the chapter to subsections...then select the Polygon Offset section.

- Halcyon

DFrey
01-06-2003, 02:01 PM
Just be aware that you can use glPolygonOffset to offset polygons, not lines. So use it when you draw the sphere, not the lines.
Another approach is to use the stencil buffer instead of polygon offset.