我试图在 GLFW 中拖动一个未装饰的窗口,但遇到了一些事件滞后,即使我正在使用 glfwWaitEvents()
我有一个光标位置回调和一个简单的循环:
// register a cursor position callback
glfwSetCursorPosCallback(win, cursor_pos_callback);
// then loop..
while(!glfwWindowShouldClose(win)) {
glfwWaitEvents();
... some rendering...
glfwSwapBuffers(win);
}
Run Code Online (Sandbox Code Playgroud)
我的光标回调对增量和更新窗口位置进行了一些简单的跟踪。
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我沿直线拖动时增量的样子
delta_x: 10 delta_y: 0 | xpos: 649 ypos: 55
delta_x: …Run Code Online (Sandbox Code Playgroud)