2013-07-31 34 views
5

Stworzyłem aplikację z Qt Creator (OS Ubuntu 13.04). Jedna funkcja tworzy okno i rysuje grafikę za pomocą biblioteki GLUT, obraz jest prawidłowy. Ale kiedy próbuję zamknąć okno i kontynuować pracę z moim programem, to kończy się. Jak mogę tego uniknąć?Jak zamknąć okno GLUT bez kończenia aplikacji?

Jest to kod z mojej funkcji:

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

wydruki wyjściowe Aplikacja”... wyszedł z kodem 0"

+0

Czy ten projekt Qt GUI? A może po prostu używasz Qt Creatora do stworzenia podstawowego projektu C++? –

+0

Tak, tworzę główne okno z Qt GUI. –

+0

W takim przypadku, jak wspomniany @JoachimPileborg, ponieważ 'glutMainLoop' nie zwraca, należy użyć wbudowanej obsługi Qt do renderowania OpenGL. –

Odpowiedz

1

Jeśli czytasz np this reference of glutMainLoop zobaczysz, że glutMainLoop nigdy nie wróci. Oznacza to, że zadzwoni on pod numer exit bezpośrednio, zamiast wrócić.

Jeśli używasz Qt, to może otwierać okna zawierające konteksty OpenGL, okna kompatybilne z resztą Qt i które możesz zamknąć w dowolnym momencie.

2

Być może zechcesz przełączyć na freeglut, który zaimplementował funkcję glutLeaveMainLoop(). Jako dokumentacja mówi:

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. 

Źródło: http://freeglut.sourceforge.net/docs/api.php