View Full Version : C++ callbacks

07-23-2004, 09:32 AM
Running linux debian w/ Qt: Thru google I finally found the following C++ example code for tesselation callbacks but:
1) if I use "CALLBACK" in the function heading - it fails not knowing "CALLBACK" - is there something I need to include in the header file for this?
2) without "CALLBACK" it fails with parse error before "{"
any ideas ?

gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (*) ( )) &vertexCallback);

void CALLBACK vertexCallback(GLvoid *vertex)
GLdouble *ptr;
ptr = (GLdouble *) vertex;
glVertex3dv((GLdouble *) ptr);
glColor3dv((GLdouble *) ptr + 3);

07-23-2004, 12:26 PM
I find:
#define CALLBACK __stdcall

in windef.h

07-26-2004, 01:16 AM
In OpenGL PG authors recomend to use next lines

#ifndef CALLBACK
#define CALLBACK

This allows you to compile your code on both Windows & Unix. If you want only Unix - get off CALLBACK from your function header

07-26-2004, 05:41 AM
thks for info:
using ifndef seems to solve header issues but callbacks are still not working(see below) - using openGL in C++ is turning into a real struggle - couldn't find any good C++ tesselation examples in google

glpanel.cpp:617: error: ISO C++ forbids taking the address of an unqualified
non-static member function to form a pointer to member function. Say `&
glpanel.cpp:617: error: converting from `void (GLPanel::*)(GLvoid*)' to `GLvoid

07-26-2004, 11:32 PM

Check out the following if you don't fancy implementing functors on your own.

function pointer (http://www.function-pointer.org/)

boost (http://www.boost.org/libs/libraries.htm#Function-objects)

// ville

07-27-2004, 06:20 AM
thks for 2 very informative links. The problem is here I just don't have the time to spend 2 weeks on exploring function pointers and figuring out how to simply draw a colored polygon. Is there a "Boost type" library for OpenGL so I don't have to spend days writing functions to draw texture fonts, polygons, curves, etc ?

07-27-2004, 06:48 PM
there is no way to send a non-static member function as a callback. just make the function static.


class X {
static void CALLBACK begin(GLenum type){}

gluTessCallback(tess, GLU_TESS_BEGIN, (void(CALLBACK*)())X::begin);