machee wrote on Tuesday, May 29, 2007:
This probably isn’t directly a GLFW issue, but I figure since it’s related I’d ask for help here. I’m using Visual C++ 2005 Express.
I’m trying to use a member function of a class as a KeyCallback function. The problem I’m having is that the way I get it working, I can’t access the other members of the class within the function.
class MyClass
{
public:
static void GLFWCALL KeyCallback(int key, int action);
bool Running;
void Init();
};
void GLFWCALL MyClass::KeyCallback(int key, int action)
{
Running = false;
}
void MyClass::Init()
{
Running=true;
glfwInit\(\);
glfwOpenWindow\( 640, 480, 0,0,0,0,0,0, GLFW\_WINDOW \);
glfwSetKeyCallback \(KeyCallback\);
while \(Running\)
\{
...
glfwSwapBuffers\(\);
\}
}
If I take “static” out, I can get to the other members of the class, but it won’t compile:
error C3867: ‘MyClass::KeyCallback’: function call missing argument list; use ‘&MyClass::KeyCallback’ to create a pointer to member
Changing the SetKeyCallback to &MyClass::KeyCallback also gives an error compiling:
error C2664: ‘glfwSetKeyCallback’ : cannot convert parameter 1 from ‘void (__thiscall MyClass::* )(int,int)’ to ‘GLFWkeyfun’
Changing the SetKeyCallback to just &KeyCallback gives:
error C2276: ‘&’ : illegal operation on bound member function expression
I’m not sure where to go from here…