PDA

View Full Version : Solving Z-Fighting in OpenGL 3 or 4



vinsonmd
01-30-2014, 05:53 AM
(I don't want to use deprecated code)

I have a wire frame polygon that forms a tube (made of four GL_TRIANGLE_STRIP) and I want to show its edges; not the interior wire frame lines though. When I add GL_LINES to show the edges, the mix with the polygon edges looks bad. I assume this is Z-Fighting?

This is my drawing command where the vector holds GL_TRIANGLE_STRIP (filled polygons) & GL_LINES (edge lines):
for(std::vector<batch_structure*>::iterator it = m_batch_structure_Vec.begin(); it!=m_batch_structure_Vec.end();it++)
{
glBindVertexArray(p_vertexArrayObject[(*it)->uiVAO_ID]);
glDrawArrays((*it)->primitiveType, 0, (*it)->nNumVerts);
}
Where batch_structure:
struct batch_structure
{
GLenum primitiveType; // What am I drawing....
GLuint uiVertexArray;
GLuint uiColorArray;
GLuint uiNormalArray;
GLuint nNumVerts; // Number of verticies in this batch
GLint uiVAO_ID;
};

I think glEdgeFlag is deprecated; plus it doesn't seem that it would work with glDrawArrays.

The SuperBible6th showed how to make two passes by drawing a filled polygon and then again draw a wire frame and used these lines of code which looks great; except I don't want to see the interior wire frame lines
// Draw black outline
glPolygonOffset(-1.0f, -1.0f); // Shift depth values
glEnable(GL_POLYGON_OFFSET_LINE);

// Draw lines antialiased
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Draw black wireframe version of geometry
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glLineWidth(2.5f);
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack);
pBatch->Draw();

How can I get clear edge lines to show up well on polygons.
Any help is appreciated.
Thanks

tonyo_au
01-30-2014, 03:44 PM
It is easy to do with a geometry shader
http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/

vinsonmd
01-30-2014, 09:37 PM
That is exactly what I needed. Thank You!