Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Polygon Triangulation And Layer Filling

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    7

    Polygon Triangulation And Layer Filling

    Hi! I'm new here. Just started working with OpenGL using MFC. I've run into a problem when filling a polygons triangulated areas with different layers.

    1st... I have a simple polygon (5 points in this example). I triangulate that polygon using googled methods to form 3 different triangles to fill. The polygon is in 3D and is a few layers thick.



    When I fill the top layer transparently everything looks smooth,



    but when filling any layer below it and moving the camera around in 3D space, I see the triangle lines between the layers.



    My code is as follows:
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glLineWidth(1);
    ////////removed code: here I draw the side quads for the 3d polygon
    glBegin(GL_TRIANGLES);
    for (j=0;j<tcount;j++){
    const Vector2d &amp;p1 = triangulationresult[j*3+0];
    const Vector2d &amp;p2 = triangulationresult[j*3+1];
    const Vector2d &amp;p3 = triangulationresult[j*3+2];
    glVertex3f(p1.GetX(),p1.GetY(), zValueForTopLayer);
    glVertex3f(p2.GetX(),p2.GetY(), zValueForTopLayer);
    glVertex3f(p3.GetX(),p3.GetY(), zValueForTopLayer);
    //if i add this code here, i see the lines for the triangles
    //glVertex3f(p1.GetX(),p1.GetY(),zValueForBottomLaye r);
    //glVertex3f(p2.GetX(),p2.GetY(), zValueForBottomLayer);
    //glVertex3f(p3.GetX(),p3.GetY(), zValueForBottomLayer);
    }
    glEnd();

    How do I fix??

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    7

    Re: Polygon Triangulation And Layer Filling

    There must be some kind of setting... a blend function or something... that smooths those triangle faces to become one face for the polygon?

    Here's some other settings I have in the openGL Init:

    // Set color to use when clearing the background.
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClearDepth(1.0f);

    // Turn on backface culling
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);

    // Turn on depth testing
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    Re: Polygon Triangulation And Layer Filling

    Make sure GL_POLYGON_SMOOTH is disabled.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    7

    Re: Polygon Triangulation And Layer Filling

    Still seeing the trianglation in the polygon with GL_POLYGON_SMOOTH disabled. (for reference I am drawing triangles, not polygons). I decided to go another route to graphically display the information I want (a solid color throughout), but for future projects I am still interested in a solution for this.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,013

    Re: Polygon Triangulation And Layer Filling

    How are you ensuring that the vertex positions are binary-identical?

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    7

    Re: Polygon Triangulation And Layer Filling

    I'm not even sure what you mean by binary-identical, but if you mean that they are the same numbers for a shared point of 2 triangles, the only verification I have is visual studio displaying them the same up to a certain decimal precision (5 points). These are floats. I tried casting all vertex coordinates into integers, and came up with the same result.

    Is that what you meant?

  7. #7
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Polygon Triangulation And Layer Filling

    Have to ask - why do U triangulate the original polygon?
    Why not use glBegin(GL_POLYGON) instead of glBegin(GL_TRIANGLES)?
    That would be the first change I'd suggest.
    Am I doing your homework for you?

  8. #8
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,013

    Re: Polygon Triangulation And Layer Filling

    Binary identical. As in "float1 == float2" is true.

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    7

    Re: Polygon Triangulation And Layer Filling

    GL_POLYGON won't draw concave polygons.

  10. #10
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Polygon Triangulation And Layer Filling

    Is there any way your triangulation routine is working inconsistently on different layers? If you draw all the polys in wireframe, does anything look funny? Also, if you draw the bottom layer without drawing the top layer, does it look o.k.?
    Am I doing your homework for 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
  •