鼠标离开 GLFW窗口后触发 GLFW 鼠标回调?
GLFW mouse callback fired after mouse leave GLFWwindow?
出于某种原因,即使在鼠标离开窗口后,我的Window::callback
也被调用。我无法找到解决方案,甚至无法找到可以提供帮助的东西。GLFW 是否有可能更新鼠标光标回调的工作方式?我想知道这是否是调用顺序问题?
窗
Window::Window(std::string title, int32_t width, int32_t height) {
// TODO: add support for monitor and share for GLFW
m_window = std::unique_ptr<GLFWwindow, GLFWdeleter>(glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr));
glfwMakeContextCurrent(m_window.get());
glfwSetWindowUserPointer(m_window.get(), this);
glfwSetCursorPosCallback(m_window.get(), Window::callback);
}
void Window::mouse_callback(double xpos, double ypos) {
std::cout << "x: " << xpos << " y: " << ypos << std::endl;
}
void Window::callback(GLFWwindow* window, double xpos, double ypos)
{
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->mouse_callback(xpos, ypos);
}
发动机
void startup() const
{
if (glfwInit() == 0)
{
LOG(kError, "GLFW init failed!");
exit(-1);
}
}
void Engine::run() {
if (m_main_window_registered)
{
glewExperimental = static_cast<GLboolean>(true);
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize glew" << std::endl;
return;
}
}
while(glfwWindowShouldClose(m_main_window->window()) == 0) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(m_main_window->window());
glfwPollEvents();
}
}
主.cpp
int main()
{
g_engine.startup();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
auto window = std::make_unique<Window>("Hello World!", 640, 480);
//window->make_current();
g_engine.registerWindow(std::move(window));
g_engine.run();
glfwTerminate();
return 0;
}
我已经弄清楚了问题(或更好地说(问题是什么。在 Windows 上,回调按预期执行,一旦鼠标离开窗口区域,回调就会停止触发。对于 OSX,窗口永远不会失去焦点,因此始终调用光标回调。要解决此问题,您只需测试坐标以确保鼠标实际上在窗口内。
相关文章:
- WinAPI挂钩鼠标
- Windows.h与GLFW.h的接口
- 无法将 GLFW 库与 Ubuntu 18.04 上的头文件链接
- 将鼠标悬停在问题上时与预期">"相关的代码错误
- 跟踪滚动条上的鼠标事件
- SendInput()鼠标移动计算
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 如何在鼠标挂钩过程中检测拖动
- 如何获取 GLFW 窗口 ID?
- Win32 发送输入鼠标移动滞后并冻结
- GLFW需要链接什么?
- 如何在OpenGL(GLFW,很高兴)中进行2D缩放?
- 将鼠标和键盘输入发送到 unity3d 游戏 (Rust)
- 鼠标离开 GLFW窗口后触发 GLFW 鼠标回调?
- GLFW 不会检测到 GLFW 窗口外的鼠标移动
- SDL2 中的 GLFW 风格的无限鼠标移动
- 使用GLFW捕捉鼠标拖动?[C++]
- GLFW - 用鼠标旋转相机的视图矩阵使其旋转
- 在GLFW中设置鼠标灵敏度
- 在GLFW中单击而不拖动鼠标