How to close and reopen a GLUT window in a loop?

2019-08-22 23:19发布

问题:

I am doing a simple OpenGL freeglut project where I need to close an OpenGL window and when given a command, reopen it in the initial state (Like a game staring again when the replay button is pressed). I want to do something like this -

while (c == 'y') {
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
    printf ("Want to play again? (y/n)\n");
    scanf ("%c", &c);
}

How can I do this? I saw about glutDestroyWindow() somewhere but couldn't figure out how to use that in my case.