如何关闭GLUT窗口而不终止应用程序?

时间:2013-07-31 13:49:39

标签: c++ qt glut

我用Qt Creator(OS Ubuntu 13.04)创建了一个应用程序。一个函数创建一个窗口并使用GLUT库绘制图形,图片是正确的。但是当我尝试关闭窗口并继续使用我的程序时,它会终止。我怎么能避免这个?

我的功能代码是:

void plot(int argc, char**argv,.../*other arguments*/)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA);
    glutCreateWindow("Green Window");
    //some code
    //...
    glutDisplayFunc( draw );
    glutMainLoop();
}        

应用程序输出打印“...以代码0退出”

3 个答案:

答案 0 :(得分:2)

如果您阅读例如this reference of glutMainLoop您会看到glutMainLoop永远不会返回。这意味着它将直接调用exit而不是返回。

如果您正在使用Qt,那么它可以打开包含OpenGL上下文的窗口,与Qt其余部分兼容的窗口以及您可以随意关闭的窗口。

答案 1 :(得分:2)

您可能希望切换到已实现功能glutLeaveMainLoop()的freeglut。正如文档所说:

The glutLeaveMainLoop function causes freeglut to stop its event loop.

Usage

void glutLeaveMainLoop ( void );

Description

The glutLeaveMainLoop function causes freeglut to stop the event loop. If the GLUT_ACTION_ON_WINDOW_CLOSE option has been set to GLUT_ACTION_CONTINUE_EXECUTION, control will return to the function which called glutMainLoop; otherwise the application will exit.

If the application has two nested calls to glutMainLoop and calls glutLeaveMainLoop, the behaviour of freeglut is undefined. It may leave only the inner nested loop or it may leave both loops. If the reader has a strong preference for one behaviour over the other he should contact the freeglut Programming Consortium and ask for the code to be fixed.

Changes From GLUT

GLUT does not include this function.

来源: http://freeglut.sourceforge.net/docs/api.php

答案 2 :(得分:0)

对于FreeGlut。如果您只想关闭用GLUT创建的窗口。看:

EBAY-SK -> EBAY
EBAY SK -> EBAY
EBAY- SK -> EBAY
EBAY -> EBAY
EBAYEBAY -> EBAY

不,谢谢。