PDA

View Full Version : How can i put a glut32-callback in a class?



igel74
11-10-2002, 06:37 AM
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
}

jmathies
11-13-2002, 07:46 PM
Originally posted by igel74:
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
}

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).]

147-2
11-18-2002, 11:41 AM
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.

nigels
11-23-2002, 04:11 PM
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/