digitalmars.D - glfw callback trouble
- Hannes (20/20) Oct 18 2005 I'm having problems with the glfwSetKeyCallback function. It is defined ...
- Ivan Senji (3/35) Oct 18 2005 I really hate these errors but it is usually a calling convention proble...
- Hannes (2/4) Oct 19 2005 This works. Thanks a lot! I wonder, where could I have found this inform...
- David Medlock (4/12) Oct 19 2005 The latest GLFW 2.5 has examples using D. GLFW is a great library. The
- Ivan Senji (4/22) Oct 19 2005 It really is great but the only thing i miss is not being able to get to...
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 GLFWkeyfunI 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
This works. Thanks a lot! I wonder, where could I have found this information by myself?My callback function looks like this:try: extern(Windows) void keyCallback(int key, int state)
Oct 19 2005
Hannes wrote:The latest GLFW 2.5 has examples using D. GLFW is a great library. The Lua support in it was started by yours truly. -DavidThis works. Thanks a lot! I wonder, where could I have found this information by myself?My callback function looks like this:try: extern(Windows) void keyCallback(int key, int state)
Oct 19 2005
David Medlock wrote:Hannes wrote:This is the reason i am using it. :)The latest GLFW 2.5 has examples using D.This works. Thanks a lot! I wonder, where could I have found this information by myself?My callback function looks like this:try: extern(Windows) void keyCallback(int key, int state)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