The gluTessCallback function defines a callback for a tessellation object.
void gluTessCallback(
GLUtesselator * tess,
GLenum which,
void (* fn)( )
);
For more information on these callbacks, see the following Remarks section.
Use gluTessCallback to specify a callback to be used by a tessellation object. If the specified callback is already defined, then it is replaced. If fn is NULL, then the existing callback becomes undefined.
The tessellation object uses these callbacks to describe how a polygon that you specify is broken into triangles.
There are two versions of each callback, one with polygon data that you can define and one without. If both versions of a particular callback are specified, the callback with the polygon data you specify will be used. The polygon_data parameter of gluTessBeginPolygon is a copy of the pointer that was specified when gluTessBeginPolygon was called.
The following are valid callbacks:
void begin (GLenum type);
void beginData (GLenum type, void * polygon_data);
Because triangle fans and triangle strips do not support edge flags, the begin callback is not called with GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP if an edge flag callback is provided. Instead, the fans and strips are converted to independent triangles. The function prototype for this callback is:
void edgeFlag (GLboolean flag);
void edgeFlagData (GLboolean flag, void * polygon_data);
void vertex (void * vertex_data);
void vertexData (void * vertex_data, void * polygon_data);
void end (void);
void endData (void * polygon_data);
The function prototype for this callback is:
void combine(GLdouble coords[3], void * vertex_data[4], GLfloat weight[4], void **outData);
The vertex is defined as a linear combination of up to four existing vertices, stored in vertex_data. The coefficients of the linear combination are given by weight; these weights always sum to 1.0. All vertex pointers are valid even when some of the weights are zero. The coords parameter gives the location of the new vertex.
Allocate another vertex, interpolate parameters using vertex_data and weight, and return the new vertex pointer in outData. This handle is supplied during rendering callbacks. Free the memory sometime after calling gluTessEndPolygon.
For example, if the polygon lies in an arbitrary plane in three-dimensional space, and you associate a color with each vertex, the GLU_TESS_COMBINE callback might look like the following:
void myCombine( GLdouble coords[3], VERTEX *d[4],
GLfloat w[4], VERTEX **dataOut )
{
VERTEX *new = new_vertex();
new->x = coords[0];
new->y = coords[1];
new->z = coords[2];
new->r = w[0]*d[0]->r + w[1]*d[1]->r + w[2]*d[2]->r +
w[3]*d[3]->r;
new->g = w[0]*d[0]->g + w[1]*d[1]->g + w[2]*d[2]->g +
w[3]*d[3]->g;
new->b = w[0]*d[0]->b + w[1]*d[1]->b + w[2]*d[2]->b +
w[3]*d[3]->b;
new->a = w[0]*d[0]->a + w[1]*d[1]->a + w[2]*d[2]->a +
w[3]*d[3]->a;
*dataOut = new;
}
When the tessellation detects an intersection, the GLU_TESS_COMBINE or GLU_TESS_COMBINE_DATA callback (see below) must be defined, and must write a non-NULL pointer into dataOut. Otherwise the GLU_TESS_NEED_COMBINE_CALLBACK error occurs, and no output is generated. (This is the only error that can occur during tessellation and rendering.)
void combineData (GLdouble coords[3], void *vertex_data[4], GLfloat weight[4], void **outData, void * polygon_data);
Call gluErrorString to retrieve character strings describing these errors. The function prototype for this callback is as follows:
void error (GLenum errno);
The GLU library recovers from the first four errors by inserting the missing call or calls. GLU_TESS_COORD_TOO_LARGE indicates that some vertex coordinate exceeded the predefined constant GLU_TESS_MAX_COORD in absolute value, and that the value has been clamped. (Coordinate values must be small enough that two can be multiplied together without overflow.) GLU_TESS_NEED_COMBINE_CALLBACK indicates that the tessellation detected an intersection between two edges in the input data, and the GLU_TESS_COMBINE or GLU_TESS_COMBINE_DATA callback was not provided. No output will be generated.
void errorData (GLenum errno, void * polygon_data);
You can directly render tessallated polygons as follows:
gluTessCallback(tess, GLU_TESS_BEGIN, glBegin);
gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv);
gluTessCallback(tess, GLU_TESS_END, glEnd);
gluTessBeginPolygon(tess, NULL);
gluTessBeginContour(tess);
gluTessVertex(tess, v, v);
. .
gluTessEndContour(tess);
gluTessEndPolygon(tess);
Store the tessellated polygon in a display list so that it does not need to be tessellated every time it is rendered.
Windows NT: Use version 3.5 and later.
Windows: Use Windows 95 and later.
Windows CE: Unsupported.
Header: Declared in glu.h.
Import Library: Link with glu32.lib.
glBegin, glEdgeFlag, glEnd, glVertex, gluDeleteTess, gluErrorString, gluNewTess, gluTessBeginPolygon, gluTessEndPolygon, gluTessVertex