2013-07-31 77 views
5

Qt Creator(OS Ubuntu 13.04)でアプリケーションを作成しました。 1つの関数はウィンドウを作成し、GLUTライブラリを使用してグラフィックを描画します。しかし、ウィンドウを閉じて自分のプログラムで作業を続けようとすると、プログラムは終了します。どうすればこれを避けることができますか?アプリケーションを終了させずに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

これはQtのGUIプロジェクトですか? Qt Creatorを使って基本的なC++プロジェクトを作成していますか? –

+0

はい、Qt GUIでメインウィンドウを作成します。 –

+0

その場合、前述の@JoachimPileborgのように、 'glutMainLoop'が返ってこないので、OpenGLレンダリングのためのQtの組み込みサポートを使うべきです。 –

答えて

1

を」...コード0" で終了しましたthis reference of glutMainLoopあなたはglutMainLoopが返されないことがわかります。つまり、返品する代わりにexitに直接電話することになります。

Qtを使用している場合は、OpenGLコンテキスト、Qtの残りの部分と互換性のあるウィンドウを開くことができ、自由に閉じることができます。

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

関連する問題