Skip to main content
gamedev.net
🔒 Locked

Depth Buffering Question

Started by Roach Jan 6, 2003 at 1:19 PM 9 replies 800+ views
Original Post
Roach
Roach
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);

[/CODE]

	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).

[CODE]

glEnable(GL_DEPTH_TEST);                                     gluSphere(globe_, globeRadius, 48, 48);
                                     
// Draw Lat/Lon takes in a radius value
drawLatLon(globeRadius + 0.1);

[/CODE]

Any ideas? Comments?

Thanks
Roach    
vincoof
vincoof
polygon offset is what you need
LockePick
LockePick
>>drawLatLon(globeRadius + 0.1);
Make the value smaller until you don''t notice the space anymore. 0.000001?

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."
vincoof
vincoof
LockePick: it should not work for two reasons :
1st- that offset is more or less efficient depending of the distance between the camera and the spheres, thus it''s hard to rule.
2nd- if solid model and wireframe model do not share the same vertices, you will more than likely see interections between both models.

Though in a (very) special case it''d be a better solution, I don''t think it''s good for that case. Nice idea to keep for further cases indeed !
Roming22
Roming22
Where do you use the function glEnable(GL_POLYGON_OFFSET_FILL)?


glEnable(GL_POLYGON_OFFSET_FILL);
draw_solid
glDisable(GL_POLYGON_OFFSET_FILL);
draw_wireframe


or


draw_solid
glEnable(GL_POLYGON_OFFSET_FILL);
draw_wireframe
glDisable(GL_POLYGON_OFFSET_FILL);


or maybe both are wrong???
vincoof
vincoof
The second will not work because you''re more than likely rendering your wireframe model with lines... so you need to enable GL_POLYGON_OFFSET_LINE instead of FILL ! Apart from that, both should work, except the fact that arguments to glPolygonOffset should be different of course.

I recommend you to read that FAQ at opengl.org
Roach
Roach
Hi Gang,
Thnaks for the responces, I do want a clarification on polyogon offset though if I could. I believe that I will not be able to use poygon offset because I am rendering the lat long grid, (which is a display list made up of Line Strips) over a gluSphere(). Can I still use polygon offset?

quote:

from OpenGL.org FAQ:

Polygon offset, as its name implies, only works with polygonal primitives. It affects only the filled primitives: GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON. Polygon offset will work when you render them with glPolygonMode setto GL_FILL, GL_LINE, or GL_POINT.

Polygon offset doesn''t affect non-polygonal primitives. The GL_POINTS, GL_LINES, GL_LINE_STRIP, and GL_LINE_LOOP primitives can''t be offset with glPolygonOffset().



Current update - I actually have the lat/lon grid looking correct (with no visual space) when I use an offset of 0.1. The problem is that I do not want to use an offset if I do not have to. (Cause if I cange the viewport, or field of view - that offset will probibly have to change as well, making the code less maintainable overall). If I need the offset, well so be it - but if I can get around it - great!

Roach
vincoof
vincoof
If you''re rendering your grid with LINES, then you can''t offset the grid : you have to offset the sphere.
But if you''re rendering your grid with POLYGONS or QUADS (or strips, triangles... any filled primitive) with glPolygonMode set to GL_LINE, then yes you can use polygon offset for your grid.

quote:

The problem is that I do not want to use an offset if I do not have to. (Cause if I cange the viewport, or field of view - that offset will probibly have to change as well, making the code less maintainable overall).

You''re absolutely right, and that''s why I do not recommend an offset *but* I do recommend a "polygon offset" which is really different for OpenGL''s depth test point of view. With a polygon offset, you can push or pull the depth of 3D objects without bothering the object''s size or distance to the viewer.
snisarenko
snisarenko
Do this

glDisable(DEPTH_TEST);
//Draw your sphere
glEnable(DEPTH_TEST);
//Draw your polygon

that should work !!!
vincoof
vincoof
quote:

that should work !!!

Not really, and to say the least not at all
Roach
Roach
The Polygon Offset did the trick!

Thanks guys!

Roach

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.