我有一个QT应用程序,在这个i creator一个opengl视图中,但是当我关闭我的opengl视图(通过按下退出按钮或'ESC')我的Qt应用程序也关闭,我知道是否是崩溃或只关闭我的程序。
这是我对opengl的一次和平
int a = qApp->arguments().
char *av = qApp->arguments().toVector().data()->toLocal8Bit().
initializeGL(&a, &av);
glutMainLoop();
这是我的InitializeGL():
void ImagemFestival::initializeGL(int * pargc, char ** argv)
{
tempoIncio = std::clock();
glutInit(pargc, argv);
//glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y);
glutCreateWindow ("User Tracker Viewer");
//glutFullScreen();
glutSetCursor(GLUT_CURSOR_NONE);
glutKeyboardFunc(glutKeyboard);
glutDisplayFunc(glutDisplay);
glutIdleFunc(glutIdle);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
这是我的glutDisplay():
void ImagemFestival::glutDisplay (void)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0, 0, -30);
// Setup the OpenGL viewpoint
glLoadIdentity();
//char texto[6];
xn::SceneMetaData sceneMD;
xn::DepthMetaData depthMD;
g_DepthGenerator.GetMetaData(depthMD);
#ifndef USE_GLES
glOrtho(0, depthMD.XRes(), depthMD.YRes(), 0, -1.0, 1.0);
#else
glOrthof(0, depthMD.XRes(), depthMD.YRes(), 0, -1.0, 1.0);
#endif
glDisable(GL_TEXTURE_2D);
if (!g_bPause)
{
// Read next available data
g_Context.WaitOneUpdateAll(g_UserGenerator);
}
// Process the data
g_DepthGenerator.GetMetaData(depthMD);
g_UserGenerator.GetUserPixels(0, sceneMD);
if(tipoImagem == IMAGEM_FESTIVAL_TIPO_FESTIVAL){
DrawDepthMap(depthMD, sceneMD);
}
else{
cv::Mat fotoRgb;
DrawRgbMap(depthMD, sceneMD,&fotoRgb);
imwrite("/home/vinicius/fotosKinect/imagem--2.jpg", fotoRgb);
}
#ifndef USE_GLES
char texto[32];
tempoFloat = 10.0-float(std::clock()-tempoIncio)/(CLOCKS_PER_SEC*0.8);
//Exibindo Tempo
snprintf(texto,sizeof(texto),"%d",(int)(tempoFloat));
textoTela(texto,0.0f,20.0f);
glutSwapBuffers();
#endif
}