Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ glutesscallback(3G) — IRIX 6.5.3f

Media Vault

Software Library

Restoration Projects

Artifacts Sought



gluTessCallback(3G)            OpenGL Reference            gluTessCallback(3G)



NAME
     gluTessCallback - define a callback for a tessellation object


C SPECIFICATION
     void gluTessCallback( GLUtesselator* tess,
                           GLenum which,
                           GLvoid (*CallBackFunc)( )


PARAMETERS
     tess          Specifies the tessellation object (created with
                   gluNewTess).

     which         Specifies the callback being defined.  The following values
                   are valid:  GLUTESSBEGIN, GLUTESSBEGINDATA,
                   GLUTESSEDGEFLAG, GLUTESSEDGEFLAGDATA,
                   GLUTESSVERTEX, GLUTESSVERTEXDATA, GLUTESSEND,
                   GLUTESSENDDATA, GLUTESSCOMBINE, GLUTESSCOMBINEDATA,
                   GLUTESSERROR, and GLUTESSERRORDATA.

     CallBackFunc  Specifies the function to be called.

DESCRIPTION
     gluTessCallback is used to indicate a callback to be used by a
     tessellation object.  If the specified callback is already defined, then
     it is replaced.  If CallBackFunc is NULL, then the existing callback
     becomes undefined.

     These callbacks are used by the tessellation object to describe how a
     polygon specified by the user is broken into triangles. Note that there
     are two versions of each callback: one with user-specified polygon data
     and one without. If both versions of a particular callback are specified
     then the callback with user-specified polygon data will be used. Note
     that "polygon_data" is a copy of the pointer that was specified when
     gluTessBeginPolygon was called.

     The legal callbacks are as follows:

     GLUTESSBEGIN
               The begin callback is invoked like glBegin to indicate the
               start of a (triangle) primitive. The function takes a single
               argument of type GLenum.  If the GLUTESSBOUNDARYONLY
               property is set to GLFALSE then the argument is set to either
               GLTRIANGLEFAN, GLTRIANGLESTRIP, or GLTRIANGLES. If the
               GLUTESSBOUNDARYONLY property is set to GLTRUE then the
               argument will be set to GLLINELOOP. The function prototype
               for this callback looks like:

                    void begin ( GLenum type );





                                                                        Page 1





gluTessCallback(3G)            OpenGL Reference            gluTessCallback(3G)



     GLUTESSBEGINDATA
               The same as the GLUTESSBEGIN callback except that it takes an
               additional pointer argument. This pointer is identical to the
               opaque pointer provided when gluTessBeginPolygon was called.
               The function prototype for this callback looks like:

                    void beginData ( GLenum type, void *polygon_data );


     GLUTESSEDGEFLAG
               The edge flag callback is similar to glEdgeFlag.  The function
               takes a single Boolean flag that indicates which edges lie on
               the polygon boundary. If the flag is GLTRUE, then each vertex
               that follows begins an edge which lies on the polygon boundary
               -- that is, an edge which separates an interior region from an
               exterior one.  If the flag is GLFALSE, then each vertex that
               follows begins an edge which lies in the polygon interior. The
               edge flag callback (if defined) is invoked before the first
               vertex callback is made.

               Since triangle fans and triangle strips do not support edge
               flags, the begin callback is not called with GLTRIANGLEFAN or
               GLTRIANGLESTRIP if an edge flag callback is provided.
               Instead, the fans and strips are converted to independent
               triangles. The function prototype for this callback looks like:

                    void edgeFlag ( GLboolean flag );


     GLUTESSEDGEFLAGDATA
               The same as the GLUTESSEDGEFLAG callback except that it
               takes an additional pointer argument. This pointer is identical
               to the opaque pointer provided when gluTessBeginPolygon was
               called. The function prototype for this callback looks like:

                    void edgeFlagData ( GLboolean flag, void *polygon_data );


     GLUTESSVERTEX
               The vertex callback is invoked between the begin and end
               callbacks.  It is similar to glVertex, and it defines the
               vertices of the triangles created by the tessellation process.
               The function takes a pointer as its only argument.  This
               pointer is identical to the opaque pointer provided by the user
               when the vertex was described (see gluTessVertex). The function
               prototype for this callback looks like:

                    void vertex ( void *vertex_data );







                                                                        Page 2





gluTessCallback(3G)            OpenGL Reference            gluTessCallback(3G)



     GLUTESSVERTEXDATA
               The same as the GLUTESSVERTEX callback except that it takes
               an additional pointer argument. This pointer is identical to
               the opaque pointer provided when gluTessBeginPolygon was
               called. The function prototype for this callback looks like:

                    void vertexData ( void *vertex_data, void *polygon_data );


     GLUTESSEND
               The end callback serves the same purpose as glEnd. It indicates
               the end of a primitive and it takes no arguments. The function
               prototype for this callback looks like:

                    void end ( void );


     GLUTESSENDDATA
               The same as the GLUTESSEND callback except that it takes an
               additional pointer argument. This pointer is identical to the
               opaque pointer provided when gluTessBeginPolygon was called.
               The function prototype for this callback looks like:

                    void endData ( void *polygon_data);


     GLUTESSCOMBINE
               The combine callback is called to create a new vertex when the
               tessellation detects an intersection, or wishes to merge
               features. The function takes four arguments: an array of three
               elements each of type GLdouble, an array of four pointers, an
               array of four elements each of type GLfloat, and a pointer to a
               pointer. The prototype looks like:

                    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 4
               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.  coords gives the location of the
               new vertex.

               The user must 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.  The user is responsible for freeing the memory
               sometime after gluTessEndPolygon is called.





                                                                        Page 3





gluTessCallback(3G)            OpenGL Reference            gluTessCallback(3G)



               For example, if the polygon lies in an arbitrary plane in 3-
               space, and we associate a color with each vertex, the
               GLUTESSCOMBINE callback might look like this:

                    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;
                    }


               If the tessellation detects an intersection, then the
               GLUTESSCOMBINE or GLUTESSCOMBINEDATA callback (see below)
               must be defined, and it must write a non-NULL pointer into
               dataOut. Otherwise the GLUTESSNEEDCOMBINECALLBACK error
               occurs, and no output is generated.

     GLUTESSCOMBINEDATA
               The same as the GLUTESSCOMBINE callback except that it takes
               an additional pointer argument. This pointer is identical to
               the opaque pointer provided when gluTessBeginPolygon was
               called. The function prototype for this callback looks like:

                    void combineData ( GLdouble coords[3], void *vertex_data[4],
                                       GLfloat weight[4], void **outData,
                                       void *polygon_data );


     GLUTESSERROR
               The error callback is called when an error is encountered.  The
               one argument is of type GLenum; it indicates the specific error
               that occurred and will be set to one of
               GLUTESSMISSINGBEGINPOLYGON, GLUTESSMISSINGENDPOLYGON,
               GLUTESSMISSINGBEGINCONTOUR, GLUTESSMISSINGENDCONTOUR,
               GLUTESSCOORDTOOLARGE, GLUTESSNEEDCOMBINECALLBACK or
               GLUOUTOFMEMORY. Character strings describing these errors
               can be retrieved with the gluErrorString call. The function
               prototype for this callback looks like:

                    void error ( GLenum errno );






                                                                        Page 4





gluTessCallback(3G)            OpenGL Reference            gluTessCallback(3G)



               The GLU library will recover from the first four errors by
               inserting the missing call(s).  GLUTESSCOORDTOOLARGE says
               that some vertex coordinate exceeded the predefined constant
               GLUTESSMAXCOORD in absolute value, and that the value has
               been clamped.  (Coordinate values must be small enough so that
               two can be multiplied together without overflow.)
               GLUTESSNEEDCOMBINECALLBACK says that the tessellation
               detected an intersection between two edges in the input data,
               and the GLUTESSCOMBINE or GLUTESSCOMBINEDATA callback was
               not provided.  No output will be generated. GLUOUTOFMEMORY
               says that there is not enough memory so no output will be
               generated.

     GLUTESSERRORDATA
               The same as the GLUTESSERROR callback except that it takes an
               additional pointer argument. This pointer is identical to the
               opaque pointer provided when gluTessBeginPolygon was called.
               The function prototype for this callback looks like:

                    void errorData ( GLenum errno, void *polygon_data );


EXAMPLE
     The following code shows how to tessellate a simple polygon and render it
     immediately:


          int i;
          GLdouble v[NVERTICES][3];
          gluTessCallback(tobj, GLU_TESS_BEGIN, glBegin);
          gluTessCallback(tobj, GLU_TESS_VERTEX, glVertex3dv);
          gluTessCallback(tobj, GLU_TESS_END, glEnd);
          /*gluTessCallback(tobj, GLU_TESS_COMBINE, myCombine);
               The COMBINE callback is needed if the polygon could have
               self-intersections or is otherwise ill-conditioned. */
          gluTessBeginPolygon(tobj, NULL);
            gluTessBeginContour(tobj);
              for (i = 0; i < NVERTICES; ++i)
                gluTessVertex(tobj, v[i], v[i]);
            gluTessEndContour(tobj);
          gluTessEndPolygon(tobj);


     Typically, the tessellated polygon should be stored in a display list so
     that it does not need to be retessellated every time it is rendered.


SEE ALSO
     glBegin, glEdgeFlag, glVertex, gluNewTess, gluErrorString, gluTessVertex,
     gluTessBeginPolygon, gluTessBeginContour, gluTessProperty, gluTessNormal





                                                                        Page 5



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026