I am currently working on an OpenGL 2.1/Freeglut project in C++ and I need to get a return value from a glut loop using the glutMainLoop() function without leaving immediately the current program. The solution I've found by now is to call the glutLeaveMainLoop() but it's leaving the program entirely.
So here's my question, is there any way to set directly a return value to any exiting Freeglut function (since glut doesn't allow actions like that), or any other technics to close the glut window without leaving the current program ?
Sorry if my question can seems idiot and thanks for reading.
int MenuStatus; //will be edit during the process
void runMainLoop( int val) //called by glutTimerFunc below
{
update();
render();
glutTimerFunc(1000 / SCREEN_FPS, runMainLoop, val);
//In this statement, I need the program to leave the glutMainLoop()
if (MenuStatus > 0)
glutLeaveMainLoop();
}
int HandleMenu(int ac, char **av)
{
glutInit(&ac, av);
glutInitContextVersion(2, 1);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
glutCreateWindow("Arcade - OpenGL");
if (!initGL())
{
std::cerr << "Unable to initialize graphics library!" << std::endl;
return 1;
}
glutKeyboardFunc(handleKeys);
glutDisplayFunc(render);
//runMainLoop callback
glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, 0 );
glutMainLoop();
//return statement never reached.
return MenuStatus;
}
Sorry about the missing code, hope it will be more understandable.