GLFW error - glfwSetMousePos on Mac OS X 10.7 with OpenGL camera

I follow the tutorials on http://opengl-tutorials.org and they are still brilliant (I'm on a Mac so I have to use OpenGL 3.2 and GLSL 1.50, not OpenGL 3.3 and GLSL 3.30). The only problem with the tutorials so far is that with the 3D camera tutorial (Tutorial 6: Keyboard and Mouse), when I move the mouse, I don't get any rotation, whatever, and if so, it will only be slow downward; even if i move the mouse in any direction.

I have compiled the above code (OpenGL 2.1 and 3.x) and will also write it by hand and it still presents this error. I don't know why this will happen. Could this be a bug with GLFW, Mac OS X, or something else?

+3


source to share


3 answers


I know this is a pretty old question, but I had the same problem so it might help. I downloaded the code from the website and in general /controls.cpp commented this line:

glfwSetMousePos(1024/2, 768/2);

      

There seems to be a bug in GLFW on MacOS for which this instruction doesn't work correctly. Hopefully they've fixed it in newer versions, but I haven't tested it yet.



On the side of the note, commenting out this line will make you work on the tutorial, but when you click on the vertical angle of the camera, you might run into some problems: if you move the mouse past the clip point (for example, lifting it up), the mouse position will keep updating, and when you move the mouse, you will have to wait until it reaches the clip point before the camera moves again.

[EDIT] Here's the complete modified code

// Reset mouse position for next frame
// EDIT : Doesn't work on Mac OS, hence the code below is a bit different from the website's
//glfwSetMousePos(1024/2, 768/2);

// Compute new orientation
horizontalAngle = 3.14f + mouseSpeed * float( 1024/2 - xpos );
verticalAngle   = mouseSpeed * float( 768/2 - ypos );

      

+2


source


Still the same problem with GLFW 3 on OS X 10.9.

To disable the cursor and thus capture it inside the window, I added it after the window was created.

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

      



Then I commented //glfwSetCursorPos(window, 1024 / 2, 768 / 2);

in controls.cpp

Mouse movement is now working. However, it appears that when viewing the cube from a certain angle, the view rotates as you move the mouse left and right, and at a different angle, the view moves left and right as it should. It's strange.

0


source


For GLFW2 on OSX, add this line to your tutorial-XX.cpp after glfwCreateWindow (..., ...,)

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

      

and then create two common shared variables /controls.cpp

double xpos_old, ypos_old;

      

finally comment out glfwSetCursorPos (window, 1024/2, 768/2); and change the angle calculation to a new setting, the idea is to get the difference between the old mousepos and the new ones. The final code should look like this:

// Reset mouse position for next frame
// glfwSetCursorPos(window, 1024/2, 768/2);
// Compute new orientation

horizontalAngle += mouseSpeed * float( xpos_old - xpos );
verticalAngle   += mouseSpeed * float( ypos_old - ypos );
xpos_old = xpos;
ypos_old = epos;

      

This works great on my mac! Hooray!

0


source







All Articles