Contents / Previous / Next


GLU Polygon Tessellation

Concave polygons, polygons containing holes, or polygons with intersecting edges must first be subdivided into simple convex polygons before they can be displayed. Such subdivision is called tessellation.

If you think a polygon may need tessellation, follow the following steps:

GLU routines to perform tessellation take as input arbitrary contours, which describe hard-to-render polygons.

GLUtriangulatorObj* gluNewTess (void);
void gluTessCallback (GLUtriangulatorObj *tobj, GLenum which, void (*fn)());
void gluDeleteTess (GLUtriangulatorObj *tobj);

Describe the input polygon:
void gluBeginPolygon (GLUtriangulatorObj *tobj);
void gluEndPolygon (GLUtriangulatorObj *tobj);
void gluNextContour (GLUtriangulatorObj *tobj, GLenum type);
void gluTessVertex (GLUtriangulatorObj *tobj, GLdouble v[3], void *data);
They produce some combination of triangles, triangle meshes, triangle fans, or lines.

Example:


tobj = gluNewTess();

gluTessCallback(...);
...

gluTessProperty( tobj, 
  GLU_TESS_WINDING_RULE,
  GLU_TESS_WINDING_POSITIVE );

gluBeginPolygon(tobj);
   gluTessVertex(tobj, v1, v1);
   gluTessVertex(tobj, v2, v2);
   gluTessVertex(tobj, v3, v3);
   gluTessVertex(tobj, v4, v4);
gluNextContour(tobj, GLU_INTERIOR);
   gluTessVertex(tobj, v5, v5);
   gluTessVertex(tobj, v6, v6);
   gluTessVertex(tobj, v7, v7);
gluEndPolygon(tobj);

gluDeleteTess(tobj);

Use the same tessellator object to render many polygons rather than allocate a new tessellator for each one. (In a multithreaded, multiprocessor environment, you may get better performance using several tessellators.)