2013-07-31 19 views
5

Qt Creator (OS Ubuntu 13.04) ile bir uygulama geliştirdim. Bir fonksiyon bir pencere oluşturur ve GLUT kütüphanesini kullanarak bir grafik çizer, resim doğrudur. Ama pencereyi kapatmaya ve programımla çalışmaya devam ettiğimde sona erer. Bundan nasıl kurtulabilirim?GLUT penceresini uygulama sonlandırmadan nasıl kapatabilirsiniz?

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

Uygulama çıkış baskılar" ... kodu 0" ile çıkıldı Eğer örneğin okursanız

+0

bu Qt GUI proje var mı? Yoksa basit bir C++ projesi yapmak için sadece Qt Creator kullanıyor musunuz? –

+0

Evet, Qt GUI ile ana pencereyi oluşturuyorum. –

+0

Bu durumda, @JoachimPileborg'un bahsettiği gibi, 'glutMainLoop' dönmediğinden, QG'nin OpenGL oluşturma için yerleşik desteğini kullanmalısınız. –

cevap

1

: my fonksiyonun kod yoktur

this reference of glutMainLoop, glutMainLoop'un hiçbir zaman döndürmeyeceğini göreceksiniz. Bu, geri dönmek yerine exit'u arayacağı anlamına gelir.

Qt kullanıyorsanız, OpenGL içerikleri içeren pencereleri, Qt'nin geri kalanıyla uyumlu olan pencereleri açabilir ve istediğiniz zaman kapatabilirsiniz.

2

glutLeaveMainLoop() işlevini uygulayan freeglut öğesine geçmek isteyebilirsiniz. dokümantasyon söylediği gibi:

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. 

Kaynak: http://freeglut.sourceforge.net/docs/api.php

İlgili konular