GLFW Window 没有关闭
GLFW Window does not close
单击关闭按钮时 window 永远不会关闭,并且永远不会调用 closeWindowCallback()。这是为什么?
运行 在 Ubuntu 18.04 下,用 gcc 编译。
#include <stdlib.h>
#include <stdio.h>
#include <GLFW/glfw3.h>
void error_callback(int error, const char *description)
{
fprintf(stdout, "Error: %s\n", description);
}
void closeWindowCallback(GLFWwindow *window)
{
printf("close\n");
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
}
GLFWwindow *window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
if (!window)
{
}
glfwMakeContextCurrent(window);
glfwSetWindowCloseCallback(window, closeWindowCallback);
while (!glfwWindowShouldClose(window))
{
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
我是从官方文档上拿来的:
while (!glfwWindowShouldClose(window))
{
render(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
您需要轮询事件以关闭 X11 window。
单击关闭按钮时 window 永远不会关闭,并且永远不会调用 closeWindowCallback()。这是为什么?
运行 在 Ubuntu 18.04 下,用 gcc 编译。
#include <stdlib.h>
#include <stdio.h>
#include <GLFW/glfw3.h>
void error_callback(int error, const char *description)
{
fprintf(stdout, "Error: %s\n", description);
}
void closeWindowCallback(GLFWwindow *window)
{
printf("close\n");
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
}
GLFWwindow *window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
if (!window)
{
}
glfwMakeContextCurrent(window);
glfwSetWindowCloseCallback(window, closeWindowCallback);
while (!glfwWindowShouldClose(window))
{
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
我是从官方文档上拿来的:
while (!glfwWindowShouldClose(window))
{
render(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
您需要轮询事件以关闭 X11 window。