Hello!
In the past I’ve requested help w/ the following in the “Beginners” forum, but to no avail. I now post in the “Windows Specific” forum hoping that a more focused audience might shed more light.
I’ve been puzzling over a problem with polygon tessellation for some time, and would appreciate some help. I am trying to use the GLU tessellation functions to render a non-convex polygon. My program compiles w/ no errors using MinGW. But, when I run it, Windows XP says it has “encountered a problem & needs to close.”
If anyone is able to get my program to run on their machine, or can see my error, I would be most thankful for your reply.
JeffBozeman
/* --------------------------------------------------------------------
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
// ------------------------------------------------------------------ //