Glfw - mouse position callback

hello,

I just started using the GLFW toolkit. Overall, it works just fine. I use the glfwSetKeyCallback() for keyboard input, but the glfwSetMousePosCallback() does not work for me. When I call it, the program locks up before ever displaying a screen, and I have to kill the process.

Instead, I call glfwGetMousePos() each frame.

What might the problem be with glfwSetMousePosCallback()?

Thanks.

According to this thread, you must set the callbacks after creating the window :
http://www.gamedev.net/community/forums/topic.asp?topic_id=406319

Thanks ZbuffeR, I’m opening the window first thing. Everything works except the mouse position callback.

Here is my simplified code:

void checkmouse(int x, int y) { … }
void checkkey(int k1, int k2) { … }

void main(int argc, char **argv)
{
glfwInit();
if (!glfwOpenWindow( xres, yres, 8, 8, 8, 0, 32, 0, GLFW_FULLSCREEN )) { glfwTerminate(); return; }
glfwSetKeyCallback( (GLFWkeyfun)(checkkey) );
//locks on next statement.
glfwSetMousePosCallback( (GLFWmouseposfun)(checkmouse) );
while(1) {
DrawGLScene();
glfwSwapBuffers();
if (glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED)) break;
}
glfwTerminate();
}

I put into my basic glfw project your glfwSetMousePosCallback( (GLFWmouseposfun)(checkmouse) ); and a checkmouse which printf x and y to console, and it works perfectly.
GLFW 2.5, Windows 2000 here.
Maybe the 2.6 version is not so robust ?

Thanks again ZbuffeR. I’m using v2.6 with Win-XP and VC-2005-Express. The program works just fine so I won’t worry about it too much. Is the mouse callback more or less efficient than a call to glfwGetMousePos()?

I recently switched to GLFW after having several irritating problems using SDL. I like it.

A callback is not useful if you are rendering frames in a tight loop and check mouse pos every frame, like you seem to be doing. So you may forget about it.
By the way, this is explained in the pdf docs provided with glfw :slight_smile: