简体   繁体   中英

GLFW Doesn't Detect Mouse Movement Outside GLFW Window

glfwSetCursorPosCallback() only runs when the mouse is inside the window, but not when outside of it.

Earlier on today, I had this function working without any problem, but for the last few hours I have been stumped trying to discover the issue.

static void cursorPositionCallback(GLFWwindow* window, double xpos, double ypos)
{
 std::cout << xpos << " : " << ypos << std::endl;
}

.......

 while (!glfw.WindowShouldClose())  
 {
     shader.ClearBuffers(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glfw.ResizeWindow(MVP); 
     glfwSetCursorPosCallback(glfw.GetWindowID(), cursorPositionCallback);
     Cube_IBO.DrawElementsInstanced(CubeIndices.size(), 2);
     glfw.SwapBuffers(); 
 }

GLFW documentation states

"This function sets the cursor position callback of the specified window, which is called when the cursor is moved".

  • Windows 10
  • Visual Studio 16.0.4
  • GLFW Version 3.3

GLFW will detect the mouse movement only when the cursor is placed inside a GLFW window, as you stated, GLFW documentation states it.

"This function sets the cursor position callback of the specified window, which is called when the cursor is moved".

..Of the specified window.. unless you were using Mac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM