digitalmars.D - glfw callback trouble
- Hannes <Hannes_member pathlink.com> Oct 18 2005
- Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> Oct 18 2005
- Hannes <Hannes_member pathlink.com> Oct 19 2005
- David Medlock <noone nowhere.com> Oct 19 2005
- Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> Oct 19 2005
I'm having problems with the glfwSetKeyCallback function. It is defined as:
void glfwSetKeyCallback( GLFWkeyfun cbfun );
GLFWkeyfun is defined as:
typedef void (* GLFWkeyfun)(int, int);
My callback function looks like this:
void keyCallback(int key, int state)
But when I try to set the callback function:
glfwSetKeyCallback(&keyCallback);
I get the following errors:
main.d(99): function glfw.glfwSetKeyCallback (GLFWkeyfun) does not match argumen
t types (void(*)(int state, int key))
main.d(99): cannot implicitly convert expression (#keyCallback) of type void(*)(
int state, int key) to GLFWkeyfun
If I explicitly cast to GLFWkeyfun, the parameters I get are nonsense. I played
a little with it and got it working this way:
void keyCallback(int state, int key, int junk) {...}
glfwSetKeyCallback(cast(GLFWkeyfun)&keyCallback);
So basically I had to switch the parameters and add a third, useless parameter.
I only found this "solution" by accident. Now I'm certain there is a correct way
to do this, this feels like an awful hack.
Oct 18 2005
Hannes wrote:I'm having problems with the glfwSetKeyCallback function. It is defined as: void glfwSetKeyCallback( GLFWkeyfun cbfun ); GLFWkeyfun is defined as: typedef void (* GLFWkeyfun)(int, int); My callback function looks like this: void keyCallback(int key, int state)
try: extern(Windows) void keyCallback(int key, int state);But when I try to set the callback function: glfwSetKeyCallback(&keyCallback); I get the following errors: main.d(99): function glfw.glfwSetKeyCallback (GLFWkeyfun) does not match argumen t types (void(*)(int state, int key)) main.d(99): cannot implicitly convert expression (#keyCallback) of type void(*)( int state, int key) to GLFWkeyfun
I really hate these errors but it is usually a calling convention problem.If I explicitly cast to GLFWkeyfun, the parameters I get are nonsense. I played a little with it and got it working this way: void keyCallback(int state, int key, int junk) {...} glfwSetKeyCallback(cast(GLFWkeyfun)&keyCallback); So basically I had to switch the parameters and add a third, useless parameter. I only found this "solution" by accident. Now I'm certain there is a correct way to do this, this feels like an awful hack.
Oct 18 2005
My callback function looks like this:
myself?
Oct 19 2005
Hannes wrote:My callback function looks like this:
try: extern(Windows) void keyCallback(int key, int state)
This works. Thanks a lot! I wonder, where could I have found this information by myself?
Lua support in it was started by yours truly. -David
Oct 19 2005
David Medlock wrote:Hannes wrote:My callback function looks like this:
try: extern(Windows) void keyCallback(int key, int state)
This works. Thanks a lot! I wonder, where could I have found this information by myself?
This is the reason i am using it. :)GLFW is a great library. The Lua support in it was started by yours truly.
It really is great but the only thing i miss is not being able to get to the HWND of the window.-David
Oct 19 2005








Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com>