我只想在屏幕的左下角和右上角之间画一条线。结果非常烦人,因为它渲染了一条从屏幕左下角到中间点的线......但是如果我用鼠标移动窗口位置,它会突然改变并正确呈现!发生了什么,我该如何解决这个问题?
我在macOS系统上运行代码并使用Xcode进行构建。
在移动窗口之前:
移动窗口后:
这是代码:
token.destroy
答案 0 :(得分:2)
这可能与该问题的最初问题无关,因为它是1.5年前发布的,但是如果您在Mac OS X Mojave上遇到此问题,则GLFW GitHub上会出现一个问题:https://github.com/glfw/glfw/issues/1334
您可以在此处查看临时解决方法。
答案 1 :(得分:0)
I ran into a similar issue on MacOS (Mojave) while going through the OpenGL Tutorial, so I figured I'd post a fix here (not my solution, see below). You can fix it by moving the window
ever so slightly after you swap buffers:
#include <GLFW/glfw3.h>
void fix_render_on_mac(GLFWwindow* window) {
#ifdef __APPLE__
static bool macMoved = false;
if(!macMoved) {
int x, y;
glfwGetWindowPos(window, &x, &y);
glfwSetWindowPos(window, ++x, y);
macMoved = true;
}
#endif
}
I recommend you slap this snippet in a header file, include it, and call fix_render_on_mac(window)
right after you call glfwPollEvents()
(or anytime after glfwSwapBuffers(window)
to be more precise). You can inline it, but if you're doing the OpenGL tutorials or need to reuse it, then it's obviously ideal to have it in a function for simple reuse.
Credit goes someone named "BrutPitt" on github. You can see the original code here. I've modified it to be a bit more minimal and slapped it in a header file.
HTH.