replacing QGLWidget in QOpenGLWidget is not working
-
I have the following slot in a program written for Qt4:
void MyGLWidget::newAVIImage(QImage image) { //image = image.mirrored(); // bindTexture(image); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.bits()); update(); }
As shown porting this to Qt5 by using QOpenGLWidget instead of QGLWidget by replacing updateGL with update and replacing bindtexture with glTexImage2D and generating and binding an unsigned int to GL_TEXTURE_2D in initializeGL. gives a white window (the original Qt4 worked fine). Also, after running the Qt5 version, trying to revert to the original Qt4 version gives a white screen with a
DirectShow renderer error for a while, then later the Qt4 version is working again.
Is there an explanation for this behavior, also what is the correct way for replacing bindtexture in QGLWidget? -
void MyGLWidget::newAVIImage(QImage image) { static int ss =0; image = image.mirrored(); // bindTexture(image); glBindTexture(GL_TEXTURE_2D, m_tex); image = image.convertToFormat(QImage::Format_RGB888); if (ss==0) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.bits()); ss=1; } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.width(), image.height(), GL_RGB, GL_UNSIGNED_BYTE, image.bits()); } update(); }
The above code solved the problem, that is using glTexImage2D for all frames was the culprit, it should be used only for the first frame. Subseqent frames should use glTexSubImage2D.
-