Hi everyone

I'm using QGraphicsView drawbackground() to draw my openGL texture

Qt Code:
  1. void
  2. Gview::drawBackground(QPainter *painters, const QRectF &rect)
  3. {
  4. if(isFirstImg){
  5. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  6. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  7. glBindTexture( GL_TEXTURE_2D, texture[0] );
  8. glTexImage2D(GL_TEXTURE_2D,
  9. 0,
  10. GL_RGB,
  11. 1920,
  12. 1080,
  13. 0,
  14. GL_RGB,
  15. GL_UNSIGNED_BYTE,
  16. m_rgbSrc );
  17.  
  18.  
  19. isFirstImg = false;
  20. }else
  21. {
  22. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  23. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  24. glBindTexture( GL_TEXTURE_2D, texture[0] );
  25. glTexSubImage2D(GL_TEXTURE_2D,
  26. 0,
  27. 0,
  28. 0,
  29. 1920,
  30. 1080,
  31. GL_RGB,
  32. GL_UNSIGNED_BYTE,
  33. m_rgbSrc);
  34. }
  35.  
  36. glViewport(0,0,(GLint)this->width(), (GLint)this->height());
  37.  
  38. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  39. glMatrixMode(GL_MODELVIEW);
  40. glLoadIdentity();
  41. glEnable(GL_TEXTURE_2D);
  42. glBindTexture(GL_TEXTURE_2D, texture[0]);
  43. glBegin(GL_QUADS);
  44. {
  45. glTexCoord2f(0.0f, 1.0f);glVertex2f(-1.0f, -1.0f);
  46. glTexCoord2f(1.0f, 1.0f);glVertex2f( 1.0f, -1.0f);
  47. glTexCoord2f(1.0f, 0.0f);glVertex2f( 1.0f, 1.0f);
  48. glTexCoord2f(0.0f, 0.0f);glVertex2f(-1.0f, 1.0f);
  49. }
  50. glEnd();
  51. glDisable(GL_TEXTURE_2D);
  52. glFlush();
  53. isUpdated = false;
  54.  
  55. }
To copy to clipboard, switch view to plain text mode 

and I add some GUI in QGraphicsScene in QGraphicsView.

Qt Code:
  1. m_scene = new QGraphicsScene();
  2. m_view = new Gview();
  3. m_view->setViewportUpdateMode(
  4. QGraphicsView::BoundingRectViewportUpdate);
  5.  
  6. m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  7. m_view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
  8. m_view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
  9. m_view->setGraphicsScene(m_scene);
  10. m_view->setGeometry(50,50,300,300);
  11. m_view->show();
  12.  
  13. QDialog *dialog = new QDialog(0);
  14. dialog->setWindowOpacity(0.5);
  15. dialog->setLayout(new QVBoxLayout);
  16. dialog->layout()->addWidget(new QLabel("Hello!"));
  17. dialog->layout()->addWidget(new QPushButton("Ok", 0));
  18. m_scene->addWidget(dialog, dialog->windowFlags());
To copy to clipboard, switch view to plain text mode 

sometime the texture is fine, sometime it isn't.

the openGL texture usually disappear in my window and remain the QDialog, if I shut the QDialog window when the programe is running, the openGL texture will be appeared.

so what's the problem??



thanks you help.