Question

In my GLUT program i have created two windows. when i try to close one window entire program shuts down. can anyone tell how to avoid it.

My code to create window is as follows

int main(int argc, char **argv) 
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(ww,wh);
    window1 = glutCreateWindow("sample");
    glutReshapeFunc(changeSize);
    glutIdleFunc(renderScene);
    glutDisplayFunc(renderScene);
    window3 = glutCreateWindow("sample2");
    glutReshapeFunc(changeSize);
    glutDisplayFunc(renderScene2);
    glutIdleFunc(renderScene2);
    glutMouseFunc(mouse);
    glutPostRedisplay();
    glutMainLoop();
    return 1;
}
Was it helpful?

Solution

I don't recall GLUT being able to close windows independently in the same thread, like that. As you only use a single glutMainLoop() call to get them going, thereby when the main loop is killed for one window, it's killed for all of them.

You could try creating the windows in their own Thread. That might work, but I'm not entirely sure.

Something else you could try, is to use GLFW instead, using GLFW, you need to create the main loop etc, yourself. Bottom line, that's much easier to use and it gives you a lot more control, over your OpenGL programs. Also if you don't already have it, you should get something like GLEW.

OTHER TIPS

You've just left the capabilities of GLUT with this demand. But you're lucky: GLUT =/= OpenGL and there are many other frameworks that will satisfy your needs. How about you take a look at Qt, which offers you not only a runtime environment and a OpenGL widget, but also a large set of widgets to draw UI elements with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top