使用GLFW相当新,我想在点击鼠标左键时将光标坐标输出到控制台。但是,我根本没有得到任何输出。
NaN
答案 0 :(得分:3)
您正尝试在键盘输入回调中输入鼠标。请注意,key
对应GLFW_KEY_*
个值。您应该设置鼠标输入回调:
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
{
double xpos, ypos;
//getting cursor position
glfwGetCursorPos(window, &xpos, &ypos);
cout << "Cursor Position at (" << xpos << " : " << ypos << endl;
}
}