How to change the position of the mouse cursor in OpenGL / Glut?

I am writing a simple game and I will control the mouse camera (using GlutPassiveMotionFunc).

I'm going to feed and scour based on the difference in mice between the callbacks, however I think it would be a good idea to “make” the mouse return to the center of the screen every time they tried to move it. Thus, their cursor will not be on the edge of the screen, and they cannot move further in this direction.

What Glut / OpenGL command can I use to reposition my mouse?

+4
source share
2 answers

Use glutWarpPointer(x, y) , where x and y (both int s) are in pixels (relative to the start of the window). For instance:

 glutWarpPointer(windowWidth / 2, windowHeight / 2); 
+10
source

Sorry for the late reply. I meant that after I use the glutWrapPointer function, if I print the x and y values, I could not catch the cursor changing, and it always displays the values ​​inside the glutWrapPointer function that I provided. What I did to fix this was moving this function inside the Animate openGl function, and it worked fine.

0
source

All Articles