void DrawPolygon(clipper::Polygons &pgs) { glColor4f(0.0f, 0.0f, 0.0f, 0.4f); GLUtesselator* tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK*)())&BeginCallback); gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK*)())&VertexCallback); gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK*)())&EndCallback); gluTessCallback(tess, GLU_TESS_COMBINE, (void (CALLBACK*)())&CombineCallback); gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK*)())&ErrorCallback); gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); gluTessBeginPolygon(tess, NULL); for (clipper::Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginContour(tess); for (clipper::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = new GLdouble[3]; vert[0] = (GLdouble)pgs[i][j].X; vert[1] = (GLdouble)pgs[i][j].Y; vert[2] = 0; AddToCleanup(vert); gluTessVertex(tess, vert, vert); } gluTessEndContour(tess); } gluTessEndPolygon(tess); DoCleanup(); glColor4f(0.0f, 0.0f, 0.0f, 0.4f); glLineWidth(1.2f); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); //GL_FALSE gluTessBeginPolygon(tess, NULL); for (clipper::Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginContour(tess); for (clipper::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = new GLdouble[3]; vert[0] = (GLdouble)pgs[i][j].X; vert[1] = (GLdouble)pgs[i][j].Y; vert[2] = 0; AddToCleanup(vert); gluTessVertex(tess, vert, vert); } gluTessEndContour(tess); } gluTessEndPolygon(tess); //final cleanup ... gluDeleteTess(tess); DoCleanup(); }
void DrawPolygon(clipper::Polygons &pgs, poly_color_type pct) { switch (pct) { case pctSubject: glColor4f(0.0f, 0.0f, 1.0f, 0.05f); break; case pctClip: glColor4f(1.0f, 0.0f, 0.0f, 0.05f); break; default: glColor4f(0.0f, 1.0f, 0.0f, 0.1f); } GLUtesselator* tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK*)())&BeginCallback); gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK*)())&VertexCallback); gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK*)())&EndCallback); gluTessCallback(tess, GLU_TESS_COMBINE, (void (CALLBACK*)())&CombineCallback); gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK*)())&ErrorCallback); if (pft == pftEvenOdd) gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); else gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); //GL_FALSE gluTessBeginPolygon(tess, NULL); for (clipper::Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginContour(tess); for (clipper::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = new GLdouble[3]; vert[0] = pgs[i][j].X; vert[1] = pgs[i][j].Y; vert[2] = 0; AddToCleanup(vert); gluTessVertex(tess, vert, vert); } gluTessEndContour(tess); } gluTessEndPolygon(tess); DoCleanup(); switch (pct) { case pctSubject: glColor4f(0.0f, 0.0f, 0.3f, 0.3f); break; case pctClip: glColor4f(0.3f, 0.0f, 0.0f, 0.3f); break; default: glColor4f(0.0f, 0.2f, 0.0f, 0.5f); } if (pct == pctSolution) glLineWidth(1.2f); else glLineWidth(1); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); //GL_FALSE gluTessBeginPolygon(tess, NULL); for (clipper::Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginContour(tess); for (clipper::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = new GLdouble[3]; vert[0] = pgs[i][j].X; vert[1] = pgs[i][j].Y; vert[2] = 0; AddToCleanup(vert); gluTessVertex(tess, vert, vert); } gluTessEndContour(tess); } gluTessEndPolygon(tess); //final cleanup ... gluDeleteTess(tess); DoCleanup(); }