C++ callbacks

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);
}

I find:
#define CALLBACK __stdcall

in windef.h

In OpenGL PG authors recomend to use next lines

#ifndef CALLBACK
#define CALLBACK
#endif

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

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::vertexCallback' glpanel.cpp:617: error: converting fromvoid (GLPanel::)(GLvoid)’ to `GLvoid

sage,

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

function pointer

boost

// ville

Ville,
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 ?

there is no way to send a non-static member function as a callback. just make the function static.

example:

 
class X {
public:
static void CALLBACK begin(GLenum type){}
};
 
gluTessCallback(tess, GLU_TESS_BEGIN, (void(CALLBACK*)())X::begin);