![]() ![]() Tessellator generates actual OpenGL commands as the following: 1 triangle strip and 1 triangle. The second example has 2 counter-clockwise (CCW) inner and outer contours (loops) and is defined in tessellate2(). The default normal value is (0,0,0), which means tessellator will compute the normal from the given vertices and winding.Ī polygon with hole Tessellation of a concave poygon with a hole If you specify the normal vector with (0,0,1), then you will always see the front face even if the winding of contour is CW (I assume the camera is looking at default direction, -Z). Void gluTessNormal(GLUtessellator *tess, GLdouble x, GLdouble y, GLdouble z) You can explicitly define the surface normal by using gluTessNormal(). If the winding is clockwise (CW), the normal vector is opposite direction, so you are looking at the back face instead of the front. Notice that the winding of this polygon is counter-clockwise (CCW), which tells the surface normal of this polygon is coming out of the plane. See the each callback function in the source file how it was recorded. The following codes are generated by tessellator and recorded in callback functions. You can record actual OpenGL commands in the callback functions, which are performed during tessellation. For this case, tessellator triangulates it with GL_TRIANGLE_FAN. OpenGL tessellator decides the most efficient primitive type while performing tessellation GL_TRIANGLE, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP and GL_LINE_LOOP. ![]() The tessellation routine of this contour is described in tessellate1(). There are 3 tessellation examples: the left is a simple concave polygon with 4 vertices, the middle one has a hole in it, and the right is a self-intersecting polygon (a star shape).ĭownload the source and binary: tessellation.zip A simple concave polygon Tessellation of a concave polygon GluTessVertex(tess, coords, vertex_data) GluTessCallback(tess, GLU_TESS_ERROR, errorCB) GluTessCallback(tess, GLU_TESS_COMBINE, combineCB) ![]() GluTessCallback(tess, GLU_TESS_VERTEX, vertexCB) GluTessCallback(tess, GLU_TESS_END, endCB) GluTessCallback(tess, GLU_TESS_BEGIN, beginCB) The following snippet code is an example of general usage. You must provide appropriate callback functions, which contain actual OpenGL commands to render the polygon, such as glBegin(), glEnd(), glVertex*(), etc. Void gluTessCallback(GLUtessellator *tess, GLUenum type, void (*fn)())ĭuring tessellation process, tessellator will call a series of callback routines when it is ready to render the tessellated polygon. It may be not only vertex coordinates but also color, normal and texture coordinates. The second parameter is the vertex coordinates required for tessellation, and the third parameter is the data used for actual rendering. All the vertices should approximately lie on the same plane. Tessellator uses these vertex coordinates to perform tessellation. GluTessVertex() specifies a vertex of a contour. Void gluTessVertex(GLUtessellator *tess, GLdouble cords, void *vertexData) ![]() It is the nested block inside gluTessBeginPolygon() and gluTessEndPolygon() block. Each contour must be wrapped within this block, gluTessBeginContour() and gluTessEndContour(). Void gluTessEndContour(GLUtessellator *tess)Ī polygon may have more than one closed contour(closed loop), for example, a polyon with a hole in it has 2 contours, inner and outer contours. Void gluTessBeginContour(GLUtessellator *tess) You must describe non-convex polygon between this block. Instead of using glBegin() and glEnd() block to describe all vertices of a polygon, you need to use tessellator-specific block, gluTessBeginPolygon() and gluTessEndPolygon(). Void gluTessEndPolygon(GLUtessellator *tess) Void gluTessBeginPolygon(GLUtessellator *tess, void *userData) If failed to create one, it returns NULL pointer. GluNewTess() creates a tessellator object and gluDeleteTess() deletes the tessellator object. OpenGL provides a collection of routines to process concave polygons to convex polygons: Finally, once tessellation is done, tessellator calls actual OpenGL commands to render the tessellated polygon through the user-defined callback routines. The basic procedure of tessellation is sending all vertex coordinates of a non-convex polygon to the tessellator instead of sending them directly to OpenGL rendering pipeline, and then tessellating the polygon by the tessellator. The left is 4-side concave polygon, the middle has a hole in it, and the right is self-intersecting contour.ĭownload: tessellation.zip, stencilTess.zip Since OpenGL accepts only convex polygons for rendering, these non-convex polygons must be tessellated before rendering. Tessellation is subdividing concave polygons or polygons with intersecting edges into convex polygons. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |