Results 1 to 6 of 6

Thread: Concave Polygon via Stencil Buffer

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2007
    Posts
    12

    Concave Polygon via Stencil Buffer

    Does anyone know of a simple "full" example where one is rending a simple (concave/convex) filled polygon using a stencil buffer. I google around, but I'm having a hard time finding actual code to step through. I've come across general algs describing what to do, but since I'm unfamiliar with stencil buffs altogether, they aren't much help (yet).

    Anyone have a simple code dump they can suggest?

    Thanks in advance...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Concave Polygon via Stencil Buffer

    You can't render concave polygons with GL. You must use several convex polygons to create your concave surface.

    After, all depends on what you want to achieve with the stencil buffer. Generally you decide about which stencil test to use and which stencil operation to do, then render your objects, change your stencil operations, render same or other objects, then use the result in a second pass.

  3. #3
    Senior Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: Concave Polygon via Stencil Buffer

    Look at this web page and find the Drawing Filled, Concave Polygons Using the Stencil Buffer section.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2007
    Posts
    12

    Re: Concave Polygon via Stencil Buffer

    Thanks... but I'm still having issues with this. I can at least stencil out my triangle fan... but it's not rending "only" the concave polygon.

    In the below image, you can see the intended polygon (outlined in red), and that the green goes outside my polygon contour and fills my entire triangle fan. I just want to fill the outlined red area.

    Does anyone see any glaring issues with my code? Thanks again everyone...



    Here's my code:
    Code :
             glClearStencil(0);
             glEnable(GL_STENCIL_TEST);
             glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
             glStencilFunc(GL_NEVER, 0, 1);
             glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
     
     
             DrawPolyon(); // Just draws using triangle fan
     
     
             glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
             glStencilFunc(GL_EQUAL, 1, 1);
             glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
             glColor3f(0.0, 1.0, 0.0);
     
             glBegin(GL_QUADS); // Draw big green box over polygon area 
             glVertex3f(-200.0f,-200.0f, -0.0f);
             glVertex3f( 200.0f,-200.0f, -0.0f);
             glVertex3f( 200.0f, 200.0f, -0.0f);
             glVertex3f(-200.0f, 200.0f, -0.0f);
             glEnd();
     
             glDisable(GL_STENCIL_TEST);
     
     
             glColor3f(1.0, 0.0, 0.0);
             glBegin(GL_QUADS);
     
             glVertex3f(xth-0.25f, yth-0.25f, 1.0f);
             glVertex3f(xth+0.25f, yth-0.25f, 1.0f);
             glVertex3f(xth+0.25f, yth+0.25f, 1.0f);
             glVertex3f(xth-0.25f, yth+0.25f, 1.0f);
     
             glEnd();

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2007
    Posts
    12

    Re: Concave Polygon via Stencil Buffer

    And I should further mention that I'm using the idea behind trinitrotoluene's URL post. If you click this, and scroll down to the Drawing Filled, Concave Polygons Using the Stencil Buffer area, I'm "trying" to implement the idea behind the image:



    Thanks again...

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2007
    Posts
    12

    Re: Concave Polygon via Stencil Buffer

    So I figured it out. My code does infact work... when you disable GL_CULL_FACE

Similar Threads

  1. concave polygon shading.
    By dmantamp in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-09-2004, 12:43 PM
  2. Concave Polys & Stencil Buffer?
    By grafixkid2000 in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-23-2003, 04:57 AM
  3. Concave Polys & Stencil Buffer
    By grafixkid2000 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-23-2003, 03:56 AM
  4. Concave polygon tesselator
    By RandyU in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-07-2000, 11:20 PM
  5. Concave polygon
    By pigpig in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-08-2000, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean