小编Key*_*ess的帖子

GLFW 鼠标事件延迟与窗口拖动

我试图在 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)

c opengl cursor-position glfw setwindowpos

5
推荐指数
2
解决办法
1093
查看次数

标签 统计

c ×1

cursor-position ×1

glfw ×1

opengl ×1

setwindowpos ×1