hide random home http://www.sgi.com/tech/openGL/mjk.xlib/subsubsection3_2_2_1.html (Silicon Surf Promotional CD, 01/1995)



Next: 2.2.2 Hierarchical Display Lists Up: 2.2 The Dinosaur Model Previous: 2.2 The Dinosaur Model

2.2.1 The GLU Tessellator

The polygons in Figure 2 are irregular and complex. For performance reasons, OpenGL directly supports drawing only convex polygons. The complex polygons that make up the sides of the dinosaur need to be built from smaller convex polygons.

Since rendering complex polygons is a common need, OpenGL supplies a set of utility routines in the OpenGL GLU library which make it easy to tessellate complex polygons. In computer graphics, tessellation is the process of breaking a complex geometric surface into simple convex polygons.

The GLU library routines for tessellation are:

gluNewTess
- create a new tessellation object.
gluTessCallback
- define a callback for a tessellation object.
gluBeginPolygon
- begin a polygon description to tessellate.
gluTessVertex
- specify a vertex for the polygon to tessellate.
gluNextContour
- mark the beginning of another contour for the polygon to tessellate.
gluEndPolygon
- finish a polygon being tessellated.
gluDeleteTess
- destroy a tessellation object.

These routines are used in the example code to tessellate the sides of the dinosaur. Notice at the beginning of the program static arrays of 2D vertices are specified for the dinosaur's body, arm, leg, and eye polygons.

To use the tessellation package, you first create a tessellation object with gluNewTess. An object of type GLUtriangulatorObj* is returned which is passed into the other polygon tessellation routines. You do not need a tessellation object for every polygon you tessellate. You might need more than one tessellation object if you were trying to tessellate more than one polygon at a time. In the sample program, a single tessellation object is used for all the polygons needing tessellation.

Once you have a tessellation object, you should set up callback routines using gluTessCallback. The way that the GLU tessellation package works is that you feed in vertices. Then the tessellation is performed and your registered callbacks are called to indicate the beginning, end, and all the vertices for the convex polygons which correctly tessellate the points you feed to the tessellator.

Look at the extrudeSolidFromPolygon routine which uses the GLU tessellation routines. To understand exactly why the callbacks are specified as they are, consult the OpenGL Reference Manual [4]. The point to notice is how a single tessellation object is set up once and callbacks are registered for it. Then gluBeginPolygon is used to start tessellating a new complex polygon. The vertices of the polygon are specified using gluTessVertex. The polygon is finished by calling gluEndPolygon.

Notice the code for tessellating the polygon lies between a glNewList and glEndList; these routines begin and end the creation of a display list. The callbacks will generate glVertex2fv calls specifying the vertices of convex polygons needed to represent the complex polygon being tessellated. Once completed, a display list is available that can render the desired complex polygon.

Consider the performance benefits of OpenGL's polygon tessellator compared with a graphics system that supplies a polygon primitive that supports non-convex polygons. A primitive which supported complex polygons would likely need to tessellate each complex polygon on the fly. Calculating a tessellation is not without cost. If you were drawing the same complex polygon more than once, it is better to do the tessellation only once. This is exactly what is achieved by creating a display list for the tessellated polygon. But if you are rendering continuously changing complex polygons, the GLU tessellator is fast enough for generating vertices on the fly for immediate-mode rendering.

Having a tessellation object not directly tied to rendering is also more flexible. Your program might need to tessellate a polygon but not actually render it. The GLU's system of callbacks just generate vertices. You can call OpenGL glVertex calls to render the vertices or supply your own special callbacks to save the vertices for your own purposes. The tessellation algorithm is accessible for your own use.

The GLU tessellator also supports multiple contours allowing disjoint polygons or polygons with holes to be tessellated. The gluNextContour routine begins a new contour.

The tessellation object is just one example of functionality in OpenGL's GLU library which supports 3D rendering without complicating the basic rendering routines in the core OpenGL API. Other GLU routines support rendering of curves and surfaces using Non-Uniform Rational B-Splines (NURBS) and tessellating boundaries of solids such as cylinders, cones, and spheres. All the GLU routines are a standard part of OpenGL.



Next: 2.2.2 Hierarchical Display Lists Up: 2.2 The Dinosaur Model Previous: 2.2 The Dinosaur Model


mjk@asd.sgi.com
Wed Oct 19 18:11:46 PDT 1994