PDA

View Full Version : Tessellation?



03-16-2004, 06:25 AM
I've been puzzling over a problem with polygon tessellation for some time, and would appreciate some help. The specifics of my problem are described in the C++ code shown below (see "Problem").
Thanks for any help you can provide.
Dana J.

/* --------------------------------------------------------------------
File: PolygonTessellation.cpp
Goal: Display a non-convex polygon (the famous "Star Trek" badge).
Problem: I get the "... has encountered a problem and need to close"
error from Windows XP as soon as I include a 3rd vertex in
my contour.
Compiled: c:\MinGW\bin\g++.exe PolygonTessellation.cpp
-o PolygonTessellation.exe -lopengl32 -lglu32 -lglut32
Platform: Windows XP Pro, Version 2002, Service Pack 1
Graphics: NVIDIA GeForce FX Go5200
-------------------------------------------------------------------- */

// --------------- namespaces --------------- //
using namespace std ;

// ---------------- includes ---------------- //
#include <iostream>
#include <GL/glut.h>

// ---------------- typedefs ---------------- //
typedef void (__stdcall * TessFuncPtr) ( ) ;

// ---------- function prototypes ----------- //
void myGLUTInitializationFunction ( int* AddrArgc, char* argv [] ) ;
void myTessellationInitializationFunction ( void ) ;
void myDisplayCallbackFunction ( void ) ;

// ----------- global variables ------------ //
GLuint starTrekDisplayList ;

// ------------------------------------------------------------------ //

int main ( int argc, char* argv [] )
{
myGLUTInitializationFunction ( &argc, argv ) ;
myTessellationInitializationFunction ( ) ;
glutMainLoop ( ) ;
} // end main

// ------------------------------------------------------------------ //

void myGLUTInitializationFunction ( int* AddrArgc, char* argv [] )
{
glutInit ( AddrArgc, argv ) ;
glutInitDisplayMode ( GLUT_RGB ) ;
glutInitWindowPosition ( 250, 150 ) ;
glutInitWindowSize ( 600, 400 ) ;
glutCreateWindow ( "PolygonTessellation" ) ;
glutDisplayFunc ( myDisplayCallbackFunction ) ;
} // end myGLUTInitializationFunction

// ------------------------------------------------------------------ //

void myTessellationInitializationFunction ( void )
{
// create tesselator object ...
GLUtesselator *myTesselator = gluNewTess ( ) ;

// function prototypes ...
TessFuncPtr beginCallback ( GLenum which ) ;
TessFuncPtr endCallback ( void ) ;
TessFuncPtr errorCallback ( GLenum errorCode ) ;

// register callback functions ...
gluTessCallback ( myTesselator, GLU_TESS_VERTEX, (TessFuncPtr) glVertex3dv ) ;
gluTessCallback ( myTesselator, GLU_TESS_BEGIN, (TessFuncPtr) beginCallback ) ;
gluTessCallback ( myTesselator, GLU_TESS_END, (TessFuncPtr) endCallback ) ;
gluTessCallback ( myTesselator, GLU_TESS_ERROR, (TessFuncPtr) errorCallback ) ;

// compile a display list for future execution ...
GLdouble starTrek [4] [3]
= { { +0.4, -0.7, 0.0 },
{ 0.0, +0.7, 0.0 },
{ -0.4, -0.7, 0.0 },
{ 0.0, 0.0, 0.0 } } ;
starTrekDisplayList = glGenLists ( 1 ) ;
glNewList ( starTrekDisplayList, GL_COMPILE ) ;
gluTessBeginPolygon ( myTesselator, NULL ) ;
gluTessBeginContour ( myTesselator ) ;
gluTessVertex ( myTesselator, starTrek[0], starTrek[0] ) ;
gluTessVertex ( myTesselator, starTrek[1], starTrek[1] ) ;
gluTessVertex ( myTesselator, starTrek[2], starTrek[2] ) ;
gluTessVertex ( myTesselator, starTrek[3], starTrek[3] ) ;
gluTessEndContour ( myTesselator ) ;
gluTessEndPolygon ( myTesselator ) ;
glEndList ( ) ;
} // end myTessellationInitializationFunction

// ------------------------------------------------------------------ //

TessFuncPtr beginCallback ( GLenum which )
{
glBegin ( which ) ;
} // end beginCallback

TessFuncPtr endCallback ( void )
{
glEnd ( ) ;
} // end endCallback

TessFuncPtr errorCallback ( GLenum errorCode )
{
cout << "Tessellation error: " << gluErrorString(errorCode) << endl ;
} // end errorCallback

// ------------------------------------------------------------------ //

void myDisplayCallbackFunction ( void )
{
glClear ( GL_COLOR_BUFFER_BIT ) ;
glCallList ( starTrekDisplayList ) ;
glFlush ( ) ;
} // end myDisplayCallbackFunction

// ------------------------------------------------------------------ //

03-28-2004, 04:45 PM
dana,
i am trying to teach myself about tessellation, and found your post during a search on the subject. i copied your code and no problem compiling. but i got your same run-time error. did you ever solve your problem? i'd be interested to hear what you might have learned.
grafick