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:
Create a new tessellation object with gluNewTess().
Use gluTessCallback() several times to register (custom) callback functions to perform operations during the tessellation.
Specify tessellation properties by calling gluTessProperty(), for example, the winding rule for the regions that should be filled.
Create and render tessellated polygons by specifying the contours of one or
more closed polygons:
gluBeginPolygon(),
gluEndPolygon(),
gluNextContour(),
gluTessVertex().
If you need to tessellate something else, you may reuse your tessellation object. If you are forever finished with your tessellation object, you may delete it with gluDeleteTess().
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.)