How can i put a glut32-callback in a class?

Hello,

i try to put the callback funktion in a class, this function uses the class. The class ist binding the function to glut to.

Have anybody an example of this situation?

Regards,
igel74

example:


//Bind “handle_resize” to glut
void inithandler()
{
glutReshapeFunc(handle_resize); //won´t work
}

//resize
GLvoid handle_resize(GLint width, GLint height)
{
if (height == 0) height=1;
if (width == 0) width=1;
transform(); //another class member
}

Originally posted by igel74:
[b]Hello,

i try to put the callback funktion in a class, this function uses the class. The class ist binding the function to glut to.

Have anybody an example of this situation?

Regards,
igel74

example:


//Bind “handle_resize” to glut
void inithandler()
{
glutReshapeFunc(handle_resize); //won´t work
}

//resize
GLvoid handle_resize(GLint width, GLint height)
{
if (height == 0) height=1;
if (width == 0) width=1;
transform(); //another class member
}[/b]

Check out “AtlAux” on google. There’s a class
in it that allows you to send functional callbacks to a class method.

Regards,
Jim
http://www.mathies.com/glfaq/

[This message has been edited by jmathies (edited 11-18-2002).]

Your handle_resize(int, int) function is redefined by the compiler to be handle_resize(YourClass&, int, int). The only way to get around that is to make your function static, but that removes you from using variables in the class which are not static as well. I don’t know exactly what you are doing, but when I program such things, for a callback I usually just use a global (C type) function which calls my in-class (C++ type) function.

You may be interested in using or
studying the GLT C++ library that
adapts GLUT callbacks into C++
virtual function calls:
http://www.nigels.com/glt/