从 Freeglut/Opengl 2.1 项目中获取 return 值
Getting a return value from a Freeglut/Opengl 2.1 project
我目前正在使用 C++ 开发一个 OpenGL 2.1/Freeglut 项目,我需要使用 glutMainLoop() 函数从过剩循环中获取一个 return 值,而不立即离开当前程序。我现在找到的解决方案是调用 glutLeaveMainLoop() 但它完全离开了程序。
所以这是我的问题,有没有办法直接为任何现有的 Freeglut 函数设置一个 return 值(因为过剩不允许这样的操作),或者任何其他技术来关闭过剩 window 不离开当前程序 ?
抱歉,如果我的问题看起来很白痴,谢谢阅读。
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;
}
抱歉缺少代码,希望它能更容易理解。
调用前添加这行代码 glutMainLoop();
:
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
或
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
根据您的需要。
我目前正在使用 C++ 开发一个 OpenGL 2.1/Freeglut 项目,我需要使用 glutMainLoop() 函数从过剩循环中获取一个 return 值,而不立即离开当前程序。我现在找到的解决方案是调用 glutLeaveMainLoop() 但它完全离开了程序。
所以这是我的问题,有没有办法直接为任何现有的 Freeglut 函数设置一个 return 值(因为过剩不允许这样的操作),或者任何其他技术来关闭过剩 window 不离开当前程序 ?
抱歉,如果我的问题看起来很白痴,谢谢阅读。
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;
}
抱歉缺少代码,希望它能更容易理解。
调用前添加这行代码 glutMainLoop();
:
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
或
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
根据您的需要。