简体   繁体   中英

GLFW Window does not close

The window never closes when clicking the close-button and closeWindowCallback() is never called. Why is that?

Running under Ubuntu 18.04, compiled with 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;
}

I took it from the official documentation:

while (!glfwWindowShouldClose(window))
{
    render(window);

    glfwSwapBuffers(window);
    glfwPollEvents();
}

You need to poll events to close the X11 window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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