gfxresult_t*opengl_finish(struct _gfxdevice*dev) { dbg("finish"); internal_t*i = (internal_t*)dev->internal; gluDeleteTess(i->tesselator);i->tesselator=0; gluDeleteTess(i->tesselator_tex);i->tesselator_tex=0; gfxresult_t*result = (gfxresult_t*)malloc(sizeof(gfxresult_t)); memset(result, 0, sizeof(gfxresult_t)); result->save = opengl_result_save; result->get = opengl_result_get; result->destroy = opengl_result_destroy; return result; }
DVRClipper::~DVRClipper(void) { if(myTess) gluDeleteTess(myTess); free(sliceVertexData); }
void ODDC::DrawPolygonsTessellated( int n, int npoints[], wxPoint points[], wxCoord xoffset, wxCoord yoffset ) { if( dc ) { int prev = 0; for( int i = 0; i < n; i++ ) { dc->DrawPolygon( npoints[i], &points[i + prev], xoffset, yoffset ); prev += npoints[i]; } } #ifdef ocpnUSE_GL else { GLUtesselator *tobj = gluNewTess(); gluTessCallback( tobj, GLU_TESS_VERTEX, (_GLUfuncptr) &ODDCvertexCallback ); gluTessCallback( tobj, GLU_TESS_BEGIN, (_GLUfuncptr) &ODDCbeginCallback ); gluTessCallback( tobj, GLU_TESS_END, (_GLUfuncptr) &ODDCendCallback ); gluTessCallback( tobj, GLU_TESS_COMBINE, (_GLUfuncptr) &ODDCcombineCallback ); gluTessCallback( tobj, GLU_TESS_ERROR, (_GLUfuncptr) &ODDCerrorCallback ); gluTessNormal( tobj, 0, 0, 1); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); gluTessProperty(tobj, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); if(glIsEnabled(GL_TEXTURE_2D)) g_bTexture2D = true; else g_bTexture2D = false; ConfigurePen(); if( ConfigureBrush() ) { gluTessBeginPolygon(tobj, NULL); int prev = 0; for( int j = 0; j < n; j++ ) { gluTessBeginContour(tobj); for( int i = 0; i < npoints[j]; i++ ) { GLvertex* vertex = new GLvertex(); gTesselatorVertices.Add( vertex ); vertex->info.x = (GLdouble) points[i + prev].x; vertex->info.y = (GLdouble) points[i + prev].y; vertex->info.z = (GLdouble) 0.0; vertex->info.r = (GLdouble) 0.0; vertex->info.g = (GLdouble) 0.0; vertex->info.b = (GLdouble) 0.0; vertex->info.a = (GLdouble) 0.0; gluTessVertex( tobj, (GLdouble*)vertex, (GLdouble*)vertex ); } gluTessEndContour( tobj ); prev += npoints[j]; } gluTessEndPolygon(tobj); } gluDeleteTess(tobj); for (unsigned int i = 0; i<gTesselatorVertices.Count(); i++) delete (GLvertex*)gTesselatorVertices.Item(i); gTesselatorVertices.Clear(); } #endif }
void GLHelper::drawFilledPolyTesselated(const PositionVector& v, bool close) { if (v.size() == 0) { return; } GLUtesselator* tobj = gluNewTess(); gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv); gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &glBegin); gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &glEnd); gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &combCallback); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); gluTessBeginPolygon(tobj, nullptr); gluTessBeginContour(tobj); double* points = new double[(v.size() + int(close)) * 3]; for (int i = 0; i != (int)v.size(); ++i) { points[3 * i] = v[i].x(); points[3 * i + 1] = v[i].y(); points[3 * i + 2] = 0; gluTessVertex(tobj, points + 3 * i, points + 3 * i); } if (close) { const int i = (int)v.size(); points[3 * i] = v[0].x(); points[3 * i + 1] = v[0].y(); points[3 * i + 2] = 0; gluTessVertex(tobj, points + 3 * i, points + 3 * i); } gluTessEndContour(tobj); gluTessEndPolygon(tobj); gluDeleteTess(tobj); delete[] points; }
Triangulate::~Triangulate() { if (mTesselator) { // if valid tesselator handle... gluDeleteTess(mTesselator); // delete tesselator handle } FreeNewVertices(); // ensure new vertices are cleaned up }
void init(void) { GLUtesselator *tobj; GLdouble rect[4][3] = { { 50.0, 50.0, 0.0}, {200.0, 50.0, 0.0}, {200.0, 200.0, 0.0}, { 50.0, 200.0, 0.0} }; GLdouble tri[3][3] = { { 75.0, 75.0, 0.0}, {125.0, 175.0, 0.0}, {175.0, 75.0, 0.0} }; GLdouble star[5][6] = { {250.0, 50.0, 0.0, 1.0, 0.0, 1.0}, {325.0, 200.0, 0.0, 1.0, 1.0, 0.0}, {400.0, 50.0, 0.0, 0.0, 1.0, 1.0}, {250.0, 150.0, 0.0, 1.0, 0.0, 0.0}, {400.0, 150.0, 0.0, 0.0, 1.0, 0.0} }; glClearColor(0.0, 0.0, 0.0, 0.0); startList = glGenLists(2); tobj = gluNewTess(); gluTessCallback(tobj, GLU_TESS_VERTEX, glVertex3dv); gluTessCallback(tobj, GLU_TESS_BEGIN, beginCallback); gluTessCallback(tobj, GLU_TESS_END, endCallback); gluTessCallback(tobj, GLU_TESS_ERROR, errorCallback); // Rectangle with a triangular hole inside. glNewList(startList, GL_COMPILE); glShadeModel(GL_FLAT); gluTessBeginPolygon(tobj, NULL); gluTessBeginContour(tobj); gluTessVertex(tobj, rect[0], rect[0]); gluTessVertex(tobj, rect[1], rect[1]); gluTessVertex(tobj, rect[2], rect[2]); gluTessVertex(tobj, rect[3], rect[3]); gluTessEndContour(tobj); gluTessBeginContour(tobj); gluTessVertex(tobj, tri[0], tri[0]); gluTessVertex(tobj, tri[1], tri[1]); gluTessVertex(tobj, tri[2], tri[2]); gluTessEndContour(tobj); gluTessEndPolygon(tobj); glEndList(); gluTessCallback(tobj, GLU_TESS_VERTEX, vertexCallback); gluTessCallback(tobj, GLU_TESS_BEGIN, beginCallback); gluTessCallback(tobj, GLU_TESS_END, endCallback); gluTessCallback(tobj, GLU_TESS_ERROR, errorCallback); gluTessCallback(tobj, GLU_TESS_COMBINE, combineCallback); // Smooth shaded, self-intersecting star. glNewList(startList + 1, GL_COMPILE); glShadeModel(GL_SMOOTH); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); gluTessBeginPolygon(tobj, NULL); gluTessBeginContour(tobj); gluTessVertex(tobj, star[0], star[0]); gluTessVertex(tobj, star[1], star[1]); gluTessVertex(tobj, star[2], star[2]); gluTessVertex(tobj, star[3], star[3]); gluTessVertex(tobj, star[4], star[4]); gluTessEndContour(tobj); gluTessEndPolygon(tobj); glEndList(); gluDeleteTess(tobj); }
void hidgl_fill_polygon (int n_coords, Coord *x, Coord *y) { int i; GLUtesselator *tobj; GLdouble *vertices; assert (n_coords > 0); vertices = malloc (sizeof(GLdouble) * n_coords * 3); tobj = gluNewTess (); gluTessCallback(tobj, GLU_TESS_BEGIN, (_GLUfuncptr)myBegin); gluTessCallback(tobj, GLU_TESS_VERTEX, (_GLUfuncptr)myVertex); gluTessCallback(tobj, GLU_TESS_COMBINE, (_GLUfuncptr)myCombine); gluTessCallback(tobj, GLU_TESS_ERROR, (_GLUfuncptr)myError); gluTessBeginPolygon (tobj, NULL); gluTessBeginContour (tobj); for (i = 0; i < n_coords; i++) { vertices [0 + i * 3] = x[i]; vertices [1 + i * 3] = y[i]; vertices [2 + i * 3] = 0.; gluTessVertex (tobj, &vertices [i * 3], &vertices [i * 3]); } gluTessEndContour (tobj); gluTessEndPolygon (tobj); gluDeleteTess (tobj); myFreeCombined (); free (vertices); }
gboolean on_expose(GtkWidget *drawing, GdkEventExpose *event, gpointer _) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1,1, -1,1, 10,-10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -5); glEnable(GL_COLOR_MATERIAL); glDisable(GL_TEXTURE_2D); glColor3f(1.0, 1.0, 1.0); /* Create vertexes */ double verts[20][3]; for (int i = 0; i < G_N_ELEMENTS(verts); i++) { float ang = 2*G_PI * i / G_N_ELEMENTS(verts); verts[i][0] = sin(ang) * (i%2+0.5) * 0.6; verts[i][1] = cos(ang) * (i%2+0.5) * 0.6; verts[i][2] = 0; } /* Draw raw polygon */ glColor4f(0.5, 0.0, 0.0, 1.0); GLUtesselator *tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, glBegin); gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv); gluTessCallback(tess, GLU_TESS_END, glEnd); gluTessBeginPolygon(tess, NULL); gluTessBeginContour(tess); for (int i = 0; i < G_N_ELEMENTS(verts); i++) gluTessVertex(tess, verts[i], verts[i]); gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); /* Draw tesselated polygon */ //glColor4f(0.0, 0.0, 0.5, 1.0); //glBegin(GL_POLYGON); //for (int i = 0; i < G_N_ELEMENTS(verts); i++) // glVertex3dv(verts[i]); //glEnd(); /* Draw outline */ glColor4f(0.8, 0.8, 0.8, 1.0); glBegin(GL_LINE_LOOP); for (int i = 0; i < G_N_ELEMENTS(verts); i++) glVertex3dv(verts[i]); glEnd(); /* Flush */ GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current(); if (gdk_gl_drawable_is_double_buffered(gldrawable)) gdk_gl_drawable_swap_buffers(gldrawable); else glFlush(); return FALSE; }
void g::render_level::compile_displaylist(const level& lev) { // clear for(vbos_t::iterator it = vbos.begin(); it != vbos.end(); it++) glDeleteBuffers(1, &it->first.first); vbos.clear(); sizes.clear(); // set vertex data typedef std::vector<std::vector<GLdouble*> > vertices_t; vertices_t vertices; for(level::polygon_container::const_iterator it = lev.polygons.begin(); it != lev.polygons.end(); it++) { vertices.push_back(std::vector<GLdouble*>()); for(level::vertex_container::const_iterator jt = it->begin(); jt != it->end(); jt++) { GLdouble* vertex = new GLdouble[3]; vertex[0] = jt->x(); vertex[1] = jt->y(); vertex[2] = 0.0; vertices.back().push_back(vertex); } } // set glu tesselator typedef void (CALLBACK* func)(); GLUtesselator* tess = gluNewTess(); BOOST_ASSERT(tess != NULL); gluTessCallback(tess, GLU_TESS_BEGIN, (func)tessbegin); gluTessCallback(tess, GLU_TESS_END, (func)tessend); gluTessCallback(tess, GLU_TESS_ERROR, (func)tesserror); gluTessCallback(tess, GLU_TESS_VERTEX, (func)tessvertex); // add to vbo for(vertices_t::iterator it = vertices.begin(); it != vertices.end(); it++) { gluTessBeginPolygon(tess, NULL); gluTessBeginContour(tess); for(vertices_t::value_type::iterator jt = it->begin(); jt != it->end(); jt++) gluTessVertex(tess, *jt, *jt); gluTessEndContour(tess); gluTessEndPolygon(tess); } for(vbos_t::iterator it = vbos.begin(); it != vbos.end(); it++) { glBindBuffer(GL_ARRAY_BUFFER, it->first.first); glBufferData(GL_ARRAY_BUFFER, it->second.size() * sizeof(GLdouble), it->second.data(), GL_STATIC_DRAW); } // cleanup gluDeleteTess(tess); for(vertices_t::iterator it = vertices.begin(); it != vertices.end(); it++) for(vertices_t::value_type::iterator jt = it->begin(); jt != it->end(); jt++) delete [] *jt; for(vbos_t::iterator it = vbos.begin(); it != vbos.end(); it++) { sizes.push_back(it->second.size()); it->second.clear(); } }
void GUIPolygon::performTesselation(SUMOReal lineWidth) const { if (getFill()) { // draw the tesselated shape double* points = new double[myShape.size() * 3]; GLUtesselator* tobj = gluNewTess(); gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv); gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &beginCallback); gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &endCallback); //gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (APIENTRY*) ()) &errorCallback); gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &combineCallback); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); gluTessBeginPolygon(tobj, NULL); gluTessBeginContour(tobj); for (size_t i = 0; i != myShape.size(); ++i) { points[3 * i] = myShape[(int) i].x(); points[3 * i + 1] = myShape[(int) i].y(); points[3 * i + 2] = 0; gluTessVertex(tobj, points + 3 * i, points + 3 * i); } gluTessEndContour(tobj); gluTessEndPolygon(tobj); gluDeleteTess(tobj); delete[] points; } else { myLineWidth = lineWidth; GLHelper::drawLine(myShape); GLHelper::drawBoxLines(myShape, myLineWidth); } //std::cout << "OpenGL says: '" << gluErrorString(glGetError()) << "'\n"; }
void drawFace(carve::poly::Face<3> *face, cRGBA fc, bool offset) { //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); GLUtesselator *tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLUTessCallback)_faceBegin); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLUTessCallback)_faceVertex); gluTessCallback(tess, GLU_TESS_END_DATA, (GLUTessCallback)_faceEnd); gluTessBeginPolygon(tess, (void *)face); gluTessBeginContour(tess); carve::geom3d::Vector g_translation; double g_scale = 1.0; std::vector<std::pair<carve::geom3d::Vector, cRGBA> > v; v.resize(face->nVertices()); for (size_t i = 0, l = face->nVertices(); i != l; ++i) { v[i] = std::make_pair(g_scale * (face->vertex(i)->v + g_translation), fc); gluTessVertex(tess, (GLdouble *)v[i].first.v, (GLvoid *)&v[i]); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); }
void DebugHooks::drawFaceLoop(const std::vector<const carve::geom3d::Vector *> &face_loop, const carve::geom3d::Vector &normal, float r, float g, float b, float a, bool lit) { if (lit) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); GLUtesselator *tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, (GLUTessCallback)glBegin); gluTessCallback(tess, GLU_TESS_VERTEX, (GLUTessCallback)glVertex3dv); gluTessCallback(tess, GLU_TESS_END, (GLUTessCallback)glEnd); glNormal3dv(normal.v); glColor4f(r, g, b, a); gluTessBeginPolygon(tess, (void *)NULL); gluTessBeginContour(tess); std::vector<carve::geom3d::Vector> v; v.resize(face_loop.size()); for (size_t i = 0, l = face_loop.size(); i != l; ++i) { v[i] = g_scale * (*face_loop[i] + g_translation); gluTessVertex(tess, (GLdouble *)v[i].v, (GLvoid *)v[i].v); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); glEnable(GL_LIGHTING); }
static void runTesselator(value contours) { CAMLparam1(contours); gluTessBeginPolygon(tobj, NULL); while (contours != Val_int(0)) { value contour=Field(contours, 0); gluTessBeginContour(tobj); while (contour != Val_int(0)) { value v=Field(contour, 0); GLdouble *r = new_vertex(Double_val(Field(v, 0)), Double_val(Field(v, 1)), Double_val(Field(v, 2))); gluTessVertex(tobj, r, (void *)r); contour = Field(contour, 1); } contours = Field(contours, 1); gluTessEndContour(tobj); } gluTessEndPolygon(tobj); gluDeleteTess(tobj); tobj = NULL; free_chunks(); CAMLreturn0; }
//---------------------------------------------------------- void ofEndShape(bool bClose){ // (close -> add the first point to the end) // ----------------------------------------------- if ((bClose == true)){ //--------------------------- if (polyVertices.size() > currentStartVertex){ double* point = new double[3]; point[0] = polyVertices[currentStartVertex][0]; point[1] = polyVertices[currentStartVertex][1]; point[2] = 0; polyVertices.push_back(point); } } //------------------------------------------------ if ((polyMode == OF_POLY_WINDING_ODD) && (drawMode == OF_OUTLINE)){ // let's just draw via another method, like glLineLoop // much, much faster, and *no* tess / computation necessary glBegin(GL_LINE_STRIP); for (int i=currentStartVertex; i< polyVertices.size(); i++) { float x = polyVertices[i][0]; float y = polyVertices[i][1]; glVertex2f(x,y); } glEnd(); } else { if ( tobj != NULL){ gluTessBeginContour( tobj); for (int i=currentStartVertex; i<polyVertices.size(); i++) { gluTessVertex( tobj, polyVertices[i],polyVertices[i]); } gluTessEndContour( tobj); } } if ( tobj != NULL){ // no matter what we did / do, we need to delete the tesselator object gluTessEndPolygon( tobj); gluDeleteTess( tobj); tobj = NULL; } // now clear the vertices on the dynamically allocated data clearTessVertices(); if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing(); }
void drawTexturedPolyhedron(carve::mesh::MeshSet<3> *poly, carve::interpolate::FaceVertexAttr<tex_t> &fv_tex, carve::interpolate::FaceAttr<GLuint> &f_tex_num) { glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); GLUtesselator *tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, (GLUTessCallback)glBegin); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLUTessCallback)tess_vertex); gluTessCallback(tess, GLU_TESS_END, (GLUTessCallback)glEnd); for (carve::mesh::MeshSet<3>::face_iter i = poly->faceBegin(); i != poly->faceEnd(); ++i) { carve::mesh::MeshSet<3>::face_t *f = *i; std::vector<vt_t> vc(f->nVertices()); bool textured = true; for (carve::mesh::MeshSet<3>::face_t::edge_iter_t e = f->begin(); e != f->end(); ++e) { vc[e.idx()].x = g_scale * (e->vert->v.x + g_translation.x); vc[e.idx()].y = g_scale * (e->vert->v.y + g_translation.y); vc[e.idx()].z = g_scale * (e->vert->v.z + g_translation.z); if (fv_tex.hasAttribute(f, e.idx())) { tex_t t = fv_tex.getAttribute(f, e.idx()); vc[e.idx()].u = t.u; vc[e.idx()].v = t.v; } else { textured = false; } } if (textured) { GLuint tex_num = f_tex_num.getAttribute(f, 0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex_num); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } else { glColor4f(0.5f, 0.6f, 0.7f, 1.0f); } glNormal3dv(f->plane.N.v); gluTessBeginPolygon(tess, (void *)&textured); gluTessBeginContour(tess); for (size_t j = 0; j != vc.size(); ++j) { gluTessVertex(tess, (GLdouble *)&vc[j], (GLvoid *)&vc[j]); } gluTessEndContour(tess); gluTessEndPolygon(tess); } gluDeleteTess(tess); glDisable(GL_TEXTURE_2D); }
static void hugsprim_gluDeleteTess_1(HugsStackPtr hugs_root) { HsPtr arg1; arg1 = hugs->getPtr(); gluDeleteTess(arg1); hugs->returnIO(hugs_root,0); }
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(); }
static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { int i; if ((gr->parent && !gr->parent->overlay_enabled) || (gr->parent && gr->parent->overlay_enabled && !gr->overlay_enabled)) { return; } #if USE_OPENGLES set_color(gr, gc); draw_array(gr, p, count, GL_LINE_STRIP); #else graphics_priv_root->dirty = 1; GLUtesselator *tess = gluNewTess(); // create a tessellator if (!tess) return; // failed to create tessellation object, return 0 GLdouble quad1[count][3]; for (i = 0; i < count; i++) { quad1[i][0] = (GLdouble) (p[i].x); quad1[i][1] = (GLdouble) (p[i].y); quad1[i][2] = 0; } // register callback functions gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB); gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB); // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB); gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB); gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB); // tessellate and compile a concave quad into display list // gluTessVertex() takes 3 params: tess object, pointer to vertex coords, // and pointer to vertex data to be passed to vertex callback. // The second param is used only to perform tessellation, and the third // param is the actual vertex data to draw. It is usually same as the second // param, but It can be more than vertex coord, for example, color, normal // and UV coords which are needed for actual drawing. // Here, we are looking at only vertex coods, so the 2nd and 3rd params are // pointing same address. glColor4f(gc->fr, gc->fg, gc->fb, gc->fa); gluTessBeginPolygon(tess, 0); // with NULL data gluTessBeginContour(tess); for (i = 0; i < count; i++) { gluTessVertex(tess, quad1[i], quad1[i]); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); // delete after tessellation #endif }
void Slice::drawPolygon(Polygons &pgs, int layer){ glColor4f(0.0f, 1.0f, 0.0f, 0.25f); GLUtesselator* tess = gluNewTess(); gluTessCallback(tess, GLU_TESS_BEGIN, (GLvoid (__stdcall *) ())&BeginCallback); gluTessCallback(tess, GLU_TESS_VERTEX, (GLvoid (__stdcall *) ())&VertexCallback); gluTessCallback(tess, GLU_TESS_END, (GLvoid (__stdcall *) ())&EndCallback); gluTessCallback(tess, GLU_TESS_COMBINE, (GLvoid (__stdcall *) ())&CombineCallback); gluTessCallback(tess, GLU_TESS_ERROR, (GLvoid (__stdcall *) ())&ErrorCallback); gluTessNormal(tess, 0.0, 0.0, 1.0); gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); //GL_FALSE gluTessBeginPolygon(tess, NULL); glPushMatrix(); glTranslated(0.0,0.0,this->layerHeight*layer); for (Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginContour(tess); for (ClipperLib::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = NewVector((GLdouble)pgs[i][j].X/1000, (GLdouble)pgs[i][j].Y/1000); gluTessVertex(tess, vert, vert); } gluTessEndContour(tess); } gluTessEndPolygon(tess); ClearVectors(); glColor4f(0.0f, 0.6f, 1.0f, 0.5f); glLineWidth(1.8f); gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); for (Polygons::size_type i = 0; i < pgs.size(); ++i) { gluTessBeginPolygon(tess, NULL); gluTessBeginContour(tess); for (ClipperLib::Polygon::size_type j = 0; j < pgs[i].size(); ++j) { GLdouble *vert = NewVector((GLdouble)pgs[i][j].X/1000, (GLdouble)pgs[i][j].Y/1000); gluTessVertex(tess, vert, vert); } glColor4f(0.0f, 0.0f, 0.8f, 0.5f); gluTessEndContour(tess); gluTessEndPolygon(tess); } //final cleanup ... gluDeleteTess(tess); ClearVectors(); glPopMatrix(); }
VRML_LAYER::~VRML_LAYER() { Clear(); if( tess ) { gluDeleteTess( tess ); tess = NULL; } }
nuiTessellator::~nuiTessellator() { if (!--mRefs) { if (mpTess) { gluDeleteTess(mpTess); mpTess = NULL; } } }
void DrawPath::calculateFillDisplayList() { if (!_filled) return; if (getNumElements() < 3) { _filled = false; return; } if (_dFillList == 0) _dFillList = glGenLists(1); assert(glGetError() == GL_NO_ERROR); assert(_dFillList != 0); glNewList(_dFillList, GL_COMPILE); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // copy our data into 3 doubles for GLU GLdouble *v = new GLdouble[getNumElements() * 3]; Vec2f ourLoc; for (int i = 0; i < getNumElements(); i++) { ourLoc = getElement(i); v[i * 3] = ourLoc.x(); v[i * 3 + 1] = ourLoc.y(); v[i * 3 + 2] = 0; //printf("%f %f\n",ourLoc.x(), ourLoc.y()); } GLUtesselator* tobj = gluNewTess(); gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (*)()) &glVertex3dv);gluTessCallback (tobj, GLU_TESS_BEGIN, (GLvoid (*)()) &glBegin);gluTessCallback (tobj, GLU_TESS_END, (GLvoid (*)()) &glEnd);gluTessCallback (tobj, GLU_TESS_ERROR, (GLvoid (*)()) &f**k);gluTessCallback (tobj, GLU_TESS_COMBINE, (GLvoid (*)()) &fuckCombine); gluTessBeginPolygon (tobj, NULL); gluTessBeginContour(tobj); for (int i = 0; i < getNumElements(); i++) gluTessVertex(tobj, v + i * 3, v + i * 3); gluTessEndContour(tobj); gluTessEndPolygon(tobj); gluDeleteTess(tobj); assert(glGetError() == GL_NO_ERROR); delete[] v; glEndList(); }
static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { int i; GLuint id = glGenLists(1); // create a display list if(!id) return id; // failed to create a list, return 0 GLUtesselator *tess = gluNewTess(); // create a tessellator if(!tess) return 0; // failed to create tessellation object, return 0 GLdouble quad1[count][3]; for (i = 0 ; i < count ; i++) { quad1[i][0]=(GLdouble)(p[i].x); quad1[i][1]=(GLdouble)(p[i].y); quad1[i][2]=0; } // register callback functions gluTessCallback(tess, GLU_TESS_BEGIN, (void (*)(void))tessBeginCB); gluTessCallback(tess, GLU_TESS_END, (void (*)(void))tessEndCB); // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB); gluTessCallback(tess, GLU_TESS_VERTEX, (void (*)(void))tessVertexCB); // tessellate and compile a concave quad into display list // gluTessVertex() takes 3 params: tess object, pointer to vertex coords, // and pointer to vertex data to be passed to vertex callback. // The second param is used only to perform tessellation, and the third // param is the actual vertex data to draw. It is usually same as the second // param, but It can be more than vertex coord, for example, color, normal // and UV coords which are needed for actual drawing. // Here, we are looking at only vertex coods, so the 2nd and 3rd params are // pointing same address. glNewList(id, GL_COMPILE); glColor4f( gc->fr, gc->fg, gc->fb, gc->fa); gluTessBeginPolygon(tess, 0); // with NULL data gluTessBeginContour(tess); for (i = 0 ; i < count ; i++) { gluTessVertex(tess, quad1[i], quad1[i]); } gluTessEndContour(tess); gluTessEndPolygon(tess); glEndList(); gluDeleteTess(tess); // delete after tessellation // Actually display the polygon. // FIXME It would maybe be better to display them before calling swap_buffers glCallList(id); }
GeneralPolygon::~GeneralPolygon() { if( _gluTesselator != NULL ) gluDeleteTess(_gluTesselator); for(unsigned int c=0; c < _contours.size() ; ++c) _contours[c].clear(); _contours.clear(); _clearCombineVertexData(); _optimalConvexTesselation.clear(); }
void FTVectoriser::MakeMesh( FTGL_DOUBLE zNormal) { if( mesh) { delete mesh; } mesh = new FTMesh; GLUtesselator* tobj = gluNewTess(); gluTessCallback( tobj, GLU_TESS_BEGIN_DATA, (ftglCallback)ftglBegin); gluTessCallback( tobj, GLU_TESS_VERTEX_DATA, (ftglCallback)ftglVertex); gluTessCallback( tobj, GLU_TESS_COMBINE_DATA, (ftglCallback)ftglCombine); gluTessCallback( tobj, GLU_TESS_END_DATA, (ftglCallback)ftglEnd); gluTessCallback( tobj, GLU_TESS_ERROR_DATA, (ftglCallback)ftglError); if( contourFlag & ft_outline_even_odd_fill) // ft_outline_reverse_fill { gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); } else { gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); } gluTessProperty( tobj, GLU_TESS_TOLERANCE, 0); gluTessNormal( tobj, 0.0, 0.0, zNormal); gluTessBeginPolygon( tobj, mesh); for( size_t c = 0; c < contours(); ++c) { const FTContour* acontour = contourList[c]; gluTessBeginContour( tobj); for( size_t p = 0; p < acontour->size(); ++p) { FTGL_DOUBLE* d = const_cast<FTGL_DOUBLE*>(&acontour->pointList[p].x); gluTessVertex( tobj, d, d); } gluTessEndContour( tobj); } gluTessEndPolygon( tobj); gluDeleteTess( tobj); }
//input plygonList must be in order - depicting a fill or void int B9Tesselator::Triangulate( const std::vector<QVector2D>* polygonList, std::vector<QVector2D> *triangleStrip) { unsigned long int i; GLUtesselator *tess = gluNewTess(); // create a tessellator if(!tess) return 0; // failed to create tessellation object, return 0 this->triStrip = triangleStrip; this->CombineVertexIndex = 0; numPolyVerts = polygonList->size(); polyverts = new GLdouble*[polygonList->size()]; for(i = 0; i < polygonList->size(); i++) { polyverts[i] = new GLdouble[3]; polyverts[i][0] = GLdouble(polygonList->at(i).x()); polyverts[i][1] = GLdouble(polygonList->at(i).y()); polyverts[i][2] = GLdouble(0.0);//zero in the z } gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); gluTessNormal(tess, 0, 0, 1); // register callback functions gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (void (CALLBACK *)())tessBeginCB); gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB); gluTessCallback(tess, GLU_TESS_ERROR_DATA, (void (CALLBACK *)())tessErrorCB); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (void (CALLBACK *)())tessVertexCB); gluTessCallback(tess, GLU_TESS_COMBINE_DATA, (void (CALLBACK *)())tessCombineCB); gluTessBeginPolygon(tess, (void*) this); gluTessBeginContour(tess); for(i = 0; i < numPolyVerts; i++) { gluTessVertex(tess, polyverts[i], polyverts[i]); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); // delete after tessellation return !(int)memoryFull; }
void glu_deletetess( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { // Define mytess struct pointer for this tesselator: MOGLDEFMYTESS; if (NULL == gluDeleteTess) mogl_glunsupported("gluDeleteTess"); // Destroy GLUtesselator: gluDeleteTess((GLUtesselator*) mytess->glutesselator); // Release destructBuffers: PsychFreeAllTempMemory(3); // Release our own data structure: PsychFreeTemp((void*) mytess, 2); }
// Cleanup routine for our tesselators and other data structures. Called from // ScreenExit.c at Screen shutdown. May be called without OpenGL active! Don't // use any GL calls here, just plain C-level operations!! void PsychCleanupSCREENFillPoly(void) { // Release tesselator object and associated data structures, if any: if (tess) { gluDeleteTess(tess); tess=NULL; } if (tempv) { free(tempv); tempv = NULL; tempvsize = 0; } return; }
GLuint Tess_Obj(int c, GLdouble ** points) { GLuint id = glGenLists(1); if (!id) { fprintf(stderr, "failed to create a list, return 0\n"); return id; } GLUtesselator *tess = gluNewTess(); if (!tess) { fprintf(stderr, "failed to create tessellation object, return 0\n"); return 0; }; tessCallback(tess); // tessellate and compile a concave quad into display list // gluTessVertex() takes 3 params: tess object, pointer to vertex coords, // and pointer to vertex data to be passed to vertex callback. // The second param is used only to perform tessellation, and the third // param is the actual vertex data to draw. It is usually same as the second // param, but It can be more than vertex coord, for example, color, normal // and UV coords which are needed for actual drawing. // Here, we are looking at only vertex coods, so the 2nd and 3rd params are // pointing same address. glNewList(id, GL_COMPILE); int i; gluTessBeginPolygon(tess, 0); gluTessBeginContour(tess); for (i = 0; i < c; i++) gluTessVertex(tess, points[i], points[i]); gluTessEndContour(tess); gluTessEndPolygon(tess); glEndList(); gluDeleteTess(tess); printf("creating Tess_Obj: %d\n", id); return id; }
//============================================================================= // // // //============================================================================= void tesselateSections() { // init tesselator GLUtesselator *tess = gluNewTess(); if (!tess) { return; } // set callbacks gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (tessFunc)cbTessBegin); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (tessFunc)cbTessVertex); gluTessCallback(tess, GLU_TESS_ERROR_DATA, (tessFunc)cbTessError); gluTessCallback(tess, GLU_TESS_COMBINE, (tessFunc)cbTessCombine); gluTessCallback(tess, GLU_TESS_END_DATA, (tessFunc)cbTessEnd); for(unsigned int i=0;i<Sections.Size(); i++) { FGLSection *sect = &Sections[i]; gluTessBeginPolygon(tess, sect); for(int j=0; j< sect->numloops; j++) { gluTessBeginContour(tess); FGLSectionLoop *loop = sect->GetLoop(j); for(int k=0; k<loop->numlines; k++) { FGLSectionLine *line = loop->GetLine(k); vertex_t *vert = line->start; GLdouble v[3] = { -(double)vert->x/(double)FRACUNIT, // negate to get proper winding 0.0, (double)vert->y/(double)FRACUNIT }; gluTessVertex(tess, v, (void*)(vert - vertexes)); } gluTessEndContour(tess); } gluTessEndPolygon(tess); sect->vertices.Push(-1337); sect->vertices.ShrinkToFit(); } gluDeleteTess(tess); }