How to use glPolygonOffset()?

glPolygonOffset() has two parameters: factor and units, but i don’t know what they mean. Though i have read OpenGL FAQ in OpenGL.org, I still can’t understand it. I set the factor and units to 1.0 which is said to be a typical use in FAQ, but it doesn’t work. I draw the object with polygonal primitives(GL_TRIANGLES) and then i want to draw two lines on it. This is my code. I write them
with the help of FAQ. but it doesn’t work.

glPolygonMode (GL_FRONT_AND_BACK,GL_LINE);

glLineWidth(2.0);

glBegin(GL_LINES);
for(int i=0; i<4;i++) {
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glVertex3f(objx[i], objy[i], objz[i]);
}
glEnd(); //draw two lines

glPushAttrib (GL_ALL_ATTRIB_BITS);

glEnable (GL_POLYGON_OFFSET_FILL);
glPolygonOffset (1.0f, 1.0f);

glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

//here draw my object with GL_TRIANGLES

glPopAttrib ();

I have also tried the reversed way, namely i first draw the object and then draw the lines. It still doesn’t work. Can anyone tell me what is wrong? How can i correctly draw a line over polygons?

thanks a lot

Polygon offset does only work for polygonal primitives. The GL_LINES primitives are not going to be affected by polygon offset, but that’s ok in your code.

The right way is to draw the exact same polygonal object once with polygon mode line and once with polygon mode fill. Don’t mix different geometries and expect perfect hidden line rasterization.

Parameters in glPolygonOffset are in windows space, so near is less than far, so your current parameters look ok.

You can decide which mode should be moved in z-direction, either pull the polygon mode line object to the front or push the triangles to the back.

Units = 1 is the smallest z value that can be distinguished in the internal representation. Factor adds a value dpending on z-slope of the triangle.

In any case, it will only draw corectly with depth test enabled.

[This message has been edited by Relic (edited 12-06-2000).]

glPolygonOffset() fixed it. Thanks.