我试图拖动GLFW未修饰的窗口,但我遇到了一些事件的滞后,即使我使用glfwWaitEvents()
GLFW鼠标事件的滞后与窗口拖动
我有一个光标位置的回调,和一个简单的循环:
// register a cursor position callback
glfwSetCursorPosCallback(win, cursor_pos_callback);
// then loop..
while(!glfwWindowShouldClose(win)) {
glfwWaitEvents();
... some rendering...
glfwSwapBuffers(win);
}
我的光标回调函数对增量和更新窗口位置做了一些简单的跟踪。
cursor_pos_callback(GLFWwindow *win, double xpos, double ypos) {
// figure out delta_x and delta_y based on cursor previous position
int delta_x, delta_y;
// update window position
if (window_drag_active) {
int x,y;
glfwGetWindowPos(window, &x, &y);
glfwSetWindowPos(window, x + delta_x, y + delta_y);
}
}
这里是三角洲的样子当我拖着一条直线
delta_x: 10 delta_y: 0 | xpos: 649 ypos: 55
delta_x: 5 delta_y: -1 | xpos: 654 ypos: 54
delta_x: 5 delta_y: 3 | xpos: 659 ypos: 57
delta_x: 5 delta_y: 2 | xpos: 664 ypos: 59
delta_x: -5 delta_y: -2 | xpos: 659 ypos: 57
delta_x: 4 delta_y: 0 | xpos: 663 ypos: 57
delta_x: 2 delta_y: 0 | xpos: 665 ypos: 57
delta_x: -3 delta_y: -3 | xpos: 662 ypos: 54
delta_x: 2 delta_y: 1 | xpos: 664 ypos: 55
delta_x: 2 delta_y: 0 | xpos: 666 ypos: 55
delta_x: 3 delta_y: 2 | xpos: 669 ypos: 57
delta_x: 1 delta_y: -1 | xpos: 670 ypos: 56
delta_x: 2 delta_y: -1 | xpos: 672 ypos: 55
delta_x: 7 delta_y: 3 | xpos: 679 ypos: 58
delta_x: 2 delta_y: -1 | xpos: 681 ypos: 57
delta_x: -2 delta_y: -3 | xpos: 679 ypos: 54
delta_x: 0 delta_y: -2 | xpos: 679 ypos: 52
delta_x: 3 delta_y: 3 | xpos: 682 ypos: 55
delta_x: -5 delta_y: -3 | xpos: 677 ypos: 52
的xpos
增量,因为它应该,然后每隔一段时间,它会向后(陈旧的事件? )
也许我的窗口运动没有与光标同步?
结果是,当我拖动窗口,它猛烈地摇晃,我几乎可以在任何地方移动它...
更新:我也曾尝试glfwSetWindowPos
逻辑移动到主循环以及没有成功 - 我仍然有同样的震惊和口吃。
更新:当我注释掉glfwSetWindowPos()
窗口不再移动(当然)但事件流现在是一致的。
这使我认为窗口的移动在快速完成时会导致颠簸运动(即前进2步,后退1步)。
谢谢你的详细解答!这绝对是解决这个问题的核心。然而,它只是部分解决了问题,抖动仍然存在,但至少它更好地遵循了光标。 –