PDA

View Full Version : glu tesselation problem

groovemaster
09-07-2005, 01:06 PM
Hi all,

I have a strange problem using glu tesselation.
I can get the callback functions to worlk with static arrays, but it won't work with dynamic memory. example:

typedef void (__stdcall *GluTessCallbackType)();
GLdouble *p1=NULL, *p2=NULL, *p3=NULL;
GLdouble poly[5][3] = { {1.0, 1.0, 0.0}, {1.0, -1.0, 0.0}, {-1.0, -1.0, 0.0}, {0.0, 0.0, 0.0}, {-1.0, 1.0, 0.0} };

void initGL
{
// .....
// create some memory and points
p1 = new GLdouble[3];
p2 = new GLdouble[3];
p3 = new GLdouble[3];

p1[0] = 0.0; p1[1] = 1.0; p1[2] = 0.0;
p2[0] = 1.0; p2[1] = 0.0; p2[2] = 0.0;
p3[0] = -1.0; p3[1] = 0.0; p3[2] = 0.0;
}

void tesselate()
{
// print test -> works
printf("p1: %f %f %f\n", p1[0], p1[1], p1[2]);
printf("p2: %f %f %f\n", p2[0], p2[1], p2[2]);
printf("p3: %f %f %f\n", p3[0], p3[1], p3[2]);

GLUtesselator* tess = gluNewTess();
if (tess == NULL)
printf("Creation failed.");

gluTessCallback (tess, GLU_TESS_BEGIN, reinterpret_cast<GluTessCallbackType>(tcbBegin) );
gluTessCallback (tess, GLU_TESS_VERTEX, reinterpret_cast<GluTessCallbackType (tcbVertex) );
gluTessCallback (tess, GLU_TESS_END, reinterpret_cast<GluTessCallbackType>(tcbEnd) );
gluTessCallback (tess, GLU_TESS_ERROR, reinterpret_cast<GluTessCallbackType>(tcbError) );

// specify polygon contour
gluTessBeginPolygon(tess, NULL);

gluTessBeginContour(tess);

// passing p1, p2, p3 gives crashes
gluTessVertex(tess, p1, p1);
gluTessVertex(tess, p2, p2);
gluTessVertex(tess, p3, p3);

/*
plain static array of GLdouble[][] type -> works
for(i=0; i<5; i++)
gluTessVertex(tess, poly[i], poly[i]);
*/

gluTessEndContour(tess);

gluTessEndPolygon(tess);
gluDeleteTess(tess);
}The program crashes when i use the dynamically allocated GLdouble*'s but not when i use static arrays. Any guesses?

Hlz
09-08-2005, 06:03 PM
Are you calling initGL?

:-)