Using tessellation I am able to cuts holes out of a polygon provided that:
-
Holes do not intersect with any edges.
-
Holes do not intersect with other holes (which I guess are edges?).
My problem is that I want to be able to cut multiple holes out of a polygon, these holes could overlap with each other as well as the edges of the main polygon.
Here is some sample code which cuts 2 intersecting holes out a a simple rectangle. If I cut either one of the “inner” shapes out it works fine, however with both it fails to draw anything at all. Do I need more callbacks??? An I missing the point here?
Thanks…
void RenderShapes()
{
GLUtriangulatorObj * tess;
static GLdouble outside[4][3] = {
{ -5, -5, 0, },
{ +5, -5, 0, },
{ +5, +5, 0, },
{ -5, +5, 0, }
};
static GLdouble inside[4][3] = {
{ -2, -1, 0, },
{ +2, -1, 0, },
{ +2, +1, 0, },
{ -2, +1, 0, }
};
static GLdouble inside2[4][3] = {
{ -1, -2, 0, },
{ +1, -2, 0, },
{ +1, +2, 0, },
{ -1, +2, 0, }
};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0, 1.0, 1.0, 0.0);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glColor3f(0.0, 0.0, 1.0);
// ** create tessellation object and register callbacks **
tess = gluNewTess();
gluTessCallback(tess, GLU_BEGIN, glBegin);
gluTessCallback(tess, GLU_VERTEX, glVertex3dv);
gluTessCallback(tess, GLU_END, glEnd);
// ** draw outside **
gluBeginPolygon(tess);
gluTessVertex(tess, outside[0], outside[0]);
gluTessVertex(tess, outside[1], outside[1]);
gluTessVertex(tess, outside[2], outside[2]);
gluTessVertex(tess, outside[3], outside[3]);
// ** draw inside 1 **
gluNextContour(tess, GLU_INTERIOR);
gluTessVertex(tess, inside[0], inside[0]);
gluTessVertex(tess, inside[1], inside[1]);
gluTessVertex(tess, inside[2], inside[2]);
gluTessVertex(tess, inside[3], inside[3]);
// ** draw inside 2 **
gluNextContour(tess, GLU_INTERIOR);
gluTessVertex(tess, inside2[0], inside2[0]);
gluTessVertex(tess, inside2[1], inside2[1]);
gluTessVertex(tess, inside2[2], inside2[2]);
gluTessVertex(tess, inside2[3], inside2[3]);
gluEndPolygon(tess);
gluDeleteTess(tess);
}