繁体   English   中英

GLFW 窗口未关闭

[英]GLFW Window does not close

单击关闭按钮时窗口永远不会关闭,并且永远不会调用 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 窗口。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM