Search code examples
c++qtglut

How to close GLUT window without terminating of application?


I've created an application with Qt Creator (OS Ubuntu 13.04). One function creates a window and draws a graphic using GLUT library, picture is right. But when I try to close window and continue working with my program, it terminates. How can I avoid this?

There is the code of my function:

void plot(int argc, char**argv,.../*other arguments*/)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA);
    glutCreateWindow("Green Window");
    //some code
    //...
    glutDisplayFunc( draw );
    glutMainLoop();
}        

Application output prints "... exited with code 0"


Solution

  • If you read e.g. this reference of glutMainLoop you will see that glutMainLoop never returns. That means it will call exit directly instead of returning.

    If you're using Qt, then it's able to open windows containing OpenGL contexts, windows compatible with the rest of Qt and which you can close at will.