glutCloseFunc无需终止应用程序 [英] glutCloseFunc without terminating application
问题描述
我用glutCreateWindow
创建了一个窗口,并使用glutMainLoop
开始了一个循环.我想结束该循环并关闭窗口,所以我使用glutLeaveMainLoop
和glutCloseFunc
销毁它.我的应用程序自动终止.
I have created a window with glutCreateWindow
and started a loop using glutMainLoop
. I want to end that loop and close the window so I use glutLeaveMainLoop
and glutCloseFunc
to destroy it. Automatically, my application terminates.
我希望该应用程序在窗口销毁后仍然存在.有可能吗?
I would like the application to persist after the window is destroyed. Is it possible?
据此链接我可以做到,但是我不知道如何.我正在使用 freeglut .
According to this link I can do it, however I don't know how. I'm using freeglut.
推荐答案
希望防止FreeGLUT在关闭窗口时退出的用户,应该考虑使用
glutSetOption
设置GLUT_ACTION_ON_WINDOW_CLOSE
.
GLUT_ACTION_ON_WINDOW_CLOSE
-控制当用户或系统关闭窗口时发生的情况:
GLUT_ACTION_ON_WINDOW_CLOSE
- Controls what happens when a window is closed by the user or system:
-
GLUT_ACTION_EXIT
将立即退出应用程序(默认情况下,GLUT的行为). -
GLUT_ACTION_GLUTMAINLOOP_RETURNS
将立即从主循环中返回. -
GLUT_ACTION_CONTINUE_EXECUTION
将继续执行其余窗口.
GLUT_ACTION_EXIT
will immediately exit the application (default, GLUT's behavior).GLUT_ACTION_GLUTMAINLOOP_RETURNS
will immediately return from the main loop.GLUT_ACTION_CONTINUE_EXECUTION
will continue execution of remaining windows.
并且来自 glutLeaveMainLoop()
:
glutLeaveMainLoop
函数使freeglut停止事件循环.如果GLUT_ACTION_ON_WINDOW_CLOSE
选项设置为GLUT_ACTION_GLUTMAINLOOP_RETURNS
或GLUT_ACTION_CONTINUE_EXECUTION
,则控制将返回到名为glutMainLoop的函数;否则,控件将返回到该函数.否则应用程序将退出.
The
glutLeaveMainLoop
function causes freeglut to stop the event loop. If theGLUT_ACTION_ON_WINDOW_CLOSE
option has been set toGLUT_ACTION_GLUTMAINLOOP_RETURNS
orGLUT_ACTION_CONTINUE_EXECUTION
, control will return to the function which called glutMainLoop; otherwise the application will exit.
将各个部分拼凑在一起:
Putting the pieces together:
#include <GL/freeglut.h>
#include <iostream>
void display()
{
glClear( GL_COLOR_BUFFER_BIT );
glutSwapBuffers();
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutCreateWindow( "GLUT" );
glutDisplayFunc( display );
glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS );
std::cout << "Before glutMainLoop()!" << std::endl;
glutMainLoop();
std::cout << "Back in main()!" << std::endl;
return 0;
}
这篇关于glutCloseFunc无需终止应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!