PDA

View Full Version : The problem of callback function gluTessCallback



Andyxia
06-30-2002, 09:05 PM
Hi,guys:

I have to ask for your help now. There is a link error when I use function point. this is the code:

gluTessCallback(tess, GLU_TESS_BEGIN , glBegin); //(errored)
gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv); //(errored)
gluTessCallback(tess, GLU_END, glEnd);
gluTessBeginPolygon(tess, (GLvoid *)0);

And the function defined as:
void gluTessCallback(
GLUtesselator * tess,
GLenum which,
void (* fn)( )
);


glBegin and glVertex3dv are the funs in OpenGL API, defined as :
void glBegin(
GLenum mode
);

void glEnd(
void
);

void glVertex4dv(
const GLdouble *v
);

I writed these codes in a C project and compiled no error. But in a MFC project, it can not be compiled, and the error message is :

error C2664: 'gluTessCallback' : cannot convert parameter 3 from 'void (unsigned int)' to 'void (__stdcall *)(void)'
None of the functions with this name in scope match the target type




Please help me have a look, :-)

Thanks,

mikael_aronsson
07-01-2002, 12:47 AM
Hi !

You need to add an extern "C" in front of each callback function, if you don't do that you get C++ functions, then you can just typecast the arguments to the correct type.

Mikael

Andyxia
07-01-2002, 06:33 PM
Thanks for your help, I find a way to correct it. Just do like this:
gluTessCallback(tess, GLU_BEGIN, (void (CALLBACK *)())glBegin);
gluTessCallback(tess, GLU_VERTEX, (void (CALLBACK *)())glVertex3dv);
Add ((CALLBACK *)()) head before function name, and converts it to what it need.