PDA

View Full Version : Passing member function pointers to GLUT



lucidmm
10-25-2002, 04:53 AM
How do I pass a member function pointer to glut?

For example, if I have:

class foo
{
public:
void mouseMotion (int x, int y);
};

How would I pass mouseMotion to glutMouseMotionFunc();?

tfpsly
10-25-2002, 05:21 AM
You cannot.
After all, in this code:
foo foobar;
GLUT has no knowledge of the foobar variable that owns the method you want to be called.

On the other hand you can use static method:

class foo {
[...]
static void mouseMotion (int x, int y);
}

glutMouseMotionFunc( foo::mouseMotion );

If required, you can store a static pointer to foobar in the foo class, and make a call to foobar->mouseMotion from foo::mouseMotion

Won
10-25-2002, 07:46 AM
What I used to do is have global C methods call member methods in global objects. I would write these adapters manually, which kind of sucked.

One option that might work for you (haven't tried it though) is to use the mem_fun<>() STL function adapter in the <functional> library.

-Won