glPolygonOffset problem is crazing for me

Hi all,

I am writing drawing code for hexa mesh data.
One element has 6 side quad.
When apply polygon offset, seem wrong like following.

glPolygonOffset(0.5, 0.5);
glEnable (GL_POLYGON_OFFSET_FILL);

But without polygon offset, seems good.

glPolygonOffset(0.0, 0.0);
glDisable (GL_POLYGON_OFFSET_FILL);

In polygon offset mode, It seems doesn’t offset with right direction.

What should I check in my code?
Is this related normal vector of vertex?

Regards.

when working with polygon offset, you have to draw your scene twice

glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1., -10.);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(0.0, 0.0, 0.0)
// draw stuff

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(1.0, 1.0, 1.0)
// now draw same stuff again

actually you dont have to call

glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1., -10.);

each time you draw the scene because

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

and

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

control if the offset is applied.

Thanks for reply.

Actually, I want to drawing edge lines using GL_LINES on the faces.
So I did applied glPolygonOffset before drawing lines.
But polygon offset result of faces are seems to wrong like above image.
How can i fix this problem?

glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer); 
glVertexPointer(3, GL_FLOAT, 0, 0); 

glPolygonOffset(0.5, 0.5);
glEnable (GL_POLYGON_OFFSET_FILL);


// draw hexa
glDrawElements(GL_QUADS, element::GetQuadDrawCount(comp_id),
	GL_UNSIGNED_INT, element::GetQuadDrawArrayPointer(comp_id));


// draw edges
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

glLineWidth(1.0f);

glDrawElements(GL_LINES, edge::GetDrawCount(comp_id),
	GL_UNSIGNED_INT, edge::GetDrawArrayPointer(comp_id));


glDisable (GL_LINE_SMOOTH);

I have a second question.
Is there any method for drawing edge lines on face without polygon offset using GL_LINES?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.