Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Solving Z-Fighting in OpenGL 3 or 4

  1. #1
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    3

    Solving Z-Fighting in OpenGL 3 or 4

    (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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,105
    It is easy to do with a geometry shader
    http://codeflow.org/entries/2012/aug...c-coordinates/

  3. #3
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    3
    That is exactly what I needed. Thank You!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •