Skip to main content
gamedev.net
🔒 Locked

PolygonOffset Error

Started by Johnny123 5 replies 1.1k views
Original Post
Johnny123
Johnny123
I am implemeting simple Silhouette outlines, using PolygonOffset, as a lot of articles mention. But the polygon fills seem to appear over the top of over-lapping polygons. Photo Sharing and Video Hosting at Photobucket Example code that I'm using: //Draw Silhouette glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( -3, -3 ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glLineWidth( 3.0f ); glColor3f( 0.0f, 0.0f, 0.0f ); glDisable( GL_LIGHTING ); Draw(); //Draw Fill glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glEnable( GL_LIGHTING ); glColor3f( 0.0f, 0.0f, 0.0f ); Draw(); //Draw Other glDisable( GL_POLYGON_OFFSET_FILL ); Draw2(); I've tried using a range of values for glPolygonOffset, but it doesn't seem to help, any other ideas that I could try?
Johnny123
Johnny123
Hi MaliciousDigit, I tried

glPolygonOffset(0.0f, 1.5f); and glPolygonOffset(0.0f, -1.5f);

Photo Sharing and Video Hosting at Photobucket Photo Sharing and Video Hosting at Photobucket

But it now shows the wireframe.
GamerYZ
GamerYZ
Use offset on Lines instead of Fill and set the number to something like 3.0 and 50.0

Remember to cull the right face at each drawing pass.
Johnny123
Johnny123
Offsetting the Lines was the first thing I tried, But I get a lot of lines that pop in and out as the camera moves. This mostly happens to polygons that are at 90 degree angles to the camera.

This doesn't happen when offsetting the Fills.

---

The poping seems to only occur when offsetting the lines backwards ( glPolygonOffset(1,1) ). I've experimented by moving the Lines Forward by -1, then the Fills by -3. Hopefully drawing the Fills above the Lines, but without the Lines too far Back to cause poping.

But it's still not looking right, is this even a viable option that I should keep experimenting with?
GamerYZ
GamerYZ
Yes it is viable. You are probably not culling the faces. When drawing fills, cull backface. And when drawing lines, cull frontface. If you just do that then unless you have geomtry that is very thin you won't even need polygon offset. Also try the numbers I gave you.
Johnny123
Johnny123
By doing that, I get the same effect as my first image, but with the Lines showing through instead of the Fills.

I have this similar set up already (With-out Polygon Offsetting), however, it doesn't work that well for concave meshes. I need to be able to draw, for example, a planar square, that's divided into a grid of triangles, without showing the complete wireframe, only the outside silhouette.

Using Polygon offset allows me to do this, but it doesn't looking right when polygons intersect.

Topic Locked

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

Sign in to reply to this topic.