View mode: basic / threaded / horizontal-split · Log in · Help
October 19, 2005
glfw callback trouble
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.
October 19, 2005
Re: glfw callback trouble
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.
> 
>
October 19, 2005
Re: glfw callback trouble
>> 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?
October 19, 2005
Re: glfw callback trouble
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?
> 
> 
The latest GLFW 2.5 has examples using D.  GLFW is a great library. The 
Lua support in it was started by yours truly.

-David
October 19, 2005
Re: glfw callback trouble
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?
>>
>>
> The latest GLFW 2.5 has examples using D.  

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
Top | Discussion index | About this forum | D home