PDA

View Full Version : Z buffer offsetting for GL_LINE



David Sankel
04-26-2011, 11:19 AM
I'm using OpenGL 4.1 core to implement a 3D line plotter. When the lines that I'm plotting intersect with the on-screen grid, it becomes quite confusing visually. Sometimes the grid occludes coplanar portions of the plotted lines.

I started looking for a line offsetting feature that works similarly to polygon offsetting but didn't encounter anything.

According to,

http://www.opengl.org/resources/faq/technical/polygonoffset.htm

, an alternative is to use glDepthRange. This seems a bit inelegant. Are there any other solutions out there?

I'm also considering drawing triangles with collinear edges (then I can use polygon offset). Does this have defined OpenGL behavior?

Are there any extensions out there that would solve this problem?

Thanks in advance,

David

Alfonse Reinheart
04-26-2011, 11:48 AM
I'm also considering drawing triangles with collinear edges (then I can use polygon offset).

A triangle with collinear edges has an area of zero and would therefore be invisible (the area is what gets rendered, not the edges).

If the glDepthRange solution seems too "inelegant" to you (even though it's typically the way this sort of thing is handled), then have you considered simply turning off depth tests when rendering the grid? If you want all your lines to appear in front of the grid, then just turn off the depth test when drawing the grid and turn it back on when drawing the lines.

mhagain
04-26-2011, 11:48 AM
Just change your projection matrix or apply a fixed Z offset in your vertex shader. It'll be tons more robust than polygon offset, won't suffer from non-linear depth buffer problems, and won't be implementation-dependent.