PDA

View Full Version : Tessellation - Callback function failure



Eric the Red
11-25-2004, 06:37 AM
I am programing using C++ Builder and
I am trying to set the callback functions with
gluTessCallback.

Setting a predefined function e.g.
gluTessCallback( tess , GLU_TESS_BEGIN , (FunctionCallback) &glBegin );
works fine, but when I try to invoke my own function
gluTessCallback( tess , GLU_TESS_COMBINE , (FunctionCallback) &combineCallback );
problems arise.
The function is called, but on returning to the OpenGL function
that invoked my function, the program seems to go into an eternal loop.

I have added essence of the source code of my test program, it is supposed to do the following:
1. Draw a left and a right square side by side.
2. Cut out a square hole of the two, the lower left corner of the hole
is somewhere in the left square and the upper right corner
is in the right square.

My source code is as follows:

double Tab[100][3];
typedef void (__stdcall *FunctionCallback)(void);

void combineCallback( GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut){
GLdouble *vertex;
vertex = (GLdouble *) malloc(3 * sizeof( GLdouble));
vertex[ 0 ] = coords[ 0 ];
vertex[ 1 ] = coords[ 1 ];
vertex[ 2 ] = coords[ 2 ];
*dataOut = vertex;
}

void TestTessellation(){
// Left square
Tab[0][0] = 0;
Tab[0][1] = 0;
Tab[0][2] = 1;

Tab[1][0] = 1000;
Tab[1][1] = 0;
Tab[1][2] = 1;

Tab[2][0] = 1000;
Tab[2][1] = 1000;
Tab[2][2] = 1;

Tab[3][0] = 0;
Tab[3][1] = 1000;
Tab[3][2] = 1;

// Right square

Tab[4][0] = 1000;
Tab[4][1] = 0;
Tab[4][2] = 1;

Tab[5][0] = 2000;
Tab[5][1] = 0;
Tab[5][2] = 1;

Tab[6][0] = 2000;
Tab[6][1] = 1000;
Tab[6][2] = 1;

Tab[7][0] = 1000;
Tab[7][1] = 1000;
Tab[7][2] = 1;

// Hole in the two squares

Tab[10][0] = 100;
Tab[10][1] = 750;
Tab[10][2] = 1;

Tab[11][0] = 1500;
Tab[11][1] = 750;
Tab[11][2] = 1;

Tab[12][0] = 1500;
Tab[12][1] = 500;
Tab[12][2] = 1;

Tab[13][0] = 100;
Tab[13][1] = 500;
Tab[13][2] = 1;

GLUtesselator* tess;
glColor3f( 1.0 , 0, 1.0 );
tess = gluNewTess();
gluTessCallback( tess , GLU_TESS_VERTEX , (FunctionCallback) &glVertex3dv );
gluTessCallback( tess , GLU_TESS_BEGIN , (FunctionCallback) &glBegin );
gluTessCallback( tess , GLU_TESS_END , (FunctionCallback) &glEnd );
gluTessCallback( tess , GLU_TESS_COMBINE , (FunctionCallback) &combineCallback );

gluTessProperty( tess , GLU_TESS_WINDING_RULE , GLU_TESS_WINDING_POSITIVE );

gluTessBeginPolygon( tess , NULL );

// Left square
gluTessBeginContour( tess );
gluTessVertex( tess , Tab[0] , Tab[0] );
gluTessVertex( tess , Tab[1] , Tab[1] );
gluTessVertex( tess , Tab[2] , Tab[2] );
gluTessVertex( tess , Tab[3] , Tab[3] );
gluTessEndContour( tess );

// right square
gluTessBeginContour( tess );
gluTessVertex( tess , Tab[4] , Tab[4] );
gluTessVertex( tess , Tab[5] , Tab[5] );
gluTessVertex( tess , Tab[6] , Tab[6] );
gluTessVertex( tess , Tab[7] , Tab[7] );
gluTessEndContour( tess );

// Hole in both squares

gluTessBeginContour( tess );
gluTessVertex( tess , Tab[10] , Tab[10] );
gluTessVertex( tess , Tab[11] , Tab[11] );
gluTessVertex( tess , Tab[12] , Tab[12] );
gluTessVertex( tess , Tab[13] , Tab[13] );
gluTessEndContour( tess );

gluTessEndPolygon( tess );
gluDeleteTess( tess );
}

I might add, that the tessellation works fine as long as the "edges of the squares" do
not intersect. If I draw one square and cut out a hole that is within the confines of that square, it runs without a hitch. Obviously no
attempt to call my "combineCallback" function is made.

Thanks for any suggestions.