PDA

View Full Version : Concave Polys & Stencil Buffer



grafixkid2000
07-23-2003, 01:29 AM
Hi,

I am trying to use the stencil buffer to render simple concave
polygons (when detected). I found the algorithm i'm using online -
but I think I don't have it right yet! Either my concave poly
disappears or it gets drawn as before (i.e. with artifcats).

This my code snippet...

// Draw poly as set of fan tris - ie 123-
// 134-145 etc.
// draw into the stencil buffer
glEnable(GL_STENCIL_TEST);
glClear( GL_STENCIL_BUFFER_BIT );
glColorMask(GL_FALSE,
GL_FALSE,
GL_FALSE,
GL_FALSE);
glStencilFunc(GL_ALWAYS, 0, 1);
glStencilOp(GL_INVERT,
GL_INVERT,
GL_INVERT);

int num_tris = num_children - 2;
for( int i=0; i<num_tris; i++ )
DrawTri(i);

// then draw poly as normal but stencil
// should limit drawing into the concave
// parts. This time turn on drawing

glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glColorMask(GL_TRUE,
GL_TRUE,
GL_TRUE,
GL_TRUE);

DrawFace();

glDisable(GL_STENCIL_TEST);

I am sure the stencilop & func are wrong but
I'm not that familiar with the stencil
buffer to know what im doing wrong...?

Any help appreciated.

Dave

Relic
07-23-2003, 02:56 AM
Crosspost. Answered in the advanced forum.