【问题标题】:GLFW Window does not closeGLFW 窗口不关闭
【发布时间】:2020-02-22 17:44:38
【问题描述】:

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

【问题讨论】:

    标签: c user-interface window glfw


    【解决方案1】:

    我取自官方文档:

    while (!glfwWindowShouldClose(window))
    {
        render(window);
    
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    

    您需要轮询事件以关闭 X11 窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-25
      • 2014-10-19
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多