6

I have the following code:

glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(1,1); // or 40,40 etc... doesnt help at all

But the lines are still z-fighting, is this common bug or something...? My lines are 1.0f thick and i draw the lines last in the scene.

Also i have disable GL_ALPHA_TEST and GL_LINE_SMOOTH and enabled GL_BLEND and GL_COLOR_LOGIC_OP

Edit: i have already tried GL_POLYGON_OFFSET_FILL, it doesnt help.

2 Answers2

13

GL_POLYGON_OFFSET_LINE only works for polygon rendering with glPolygonMode(GL_FRONT_AND_BACK, GL_LINE). If you're drawing primitives with GL_LINES it doesn't work. In this case you'll have to manually offset the vertices.

Andreas Brinck
  • 51,293
  • 14
  • 84
  • 114
  • Ah, so i have to draw the lines with polygon mode then –  Jan 07 '10 at 13:15
  • Drawing lines as infinitely thin polygons will not work well; GL computes the normal and uses that to offset the vertices. In this case, the normal to the polygon you are drawing will be a 0 length vector. – Tarydon Jan 07 '10 at 13:17
  • @Tarydon This is not what I'm suggesting, `glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)` is the built in wireframe mode of OpenGL. – Andreas Brinck Jan 07 '10 at 13:20
  • @Andreas: Apologies. My comment was directed at Newbie's observation that he wanted to *draw the lines with polygon mode*. – Tarydon Jan 07 '10 at 13:56
  • 1
    or alternatively, offset the polygons you draw your lines over (see http://www.opengl.org/resources/faq/technical/polygonoffset.htm) – Bahbar Jan 07 '10 at 13:59
  • yeah im using the GL_QUADS and the wireframe mode, works perfectly, thanks. –  Jan 09 '10 at 01:05
  • +1 on this answer; it is explained also at question 13.040 at the page posted by Bahbar – Zac Jun 20 '13 at 14:30
4

Try enabling GL_POLYGON_OFFSET_FILL instead. (I presume the lines are depth-fighting with polygons you have rendered earlier?)

Tarydon
  • 5,097
  • 23
  • 24