[Qt-interest] [OpenGL] How implement GLWidget::resizeGL for 2D bitmap texture?

Ed Sutton ESutton at fescorp.com
Fri Jun 19 20:33:11 CEST 2009


I am a Linux/OpenGL newbie trying to convert my GLUT application that draws video frames as 2-D bitmap textures to use QT4 QGLWidget.
      
How can I implement the OpenGL equivalent of glutDisplayFunc(&paintGL) for the QT4 GLWidget::resizeGL() method?
      
I tried simply calling paintGL() from GLWidget::resizeGL(). What am I missing?
      
Thanks in advance for any tips or direction,
      
-Ed
      
// Using QT 4
// GLWidget is derived from QGLWidget
class GLWidget : public QGLWidget{};

void GLWidget::resizeGL(int width, int height)
{
   // ToDo: Under glut, glutDisplayFunc(&paintGL) worked
   // Under QT what is the equivalent?
}

void GLWidget::initializeGL()
{
   glEnable(GL_DOUBLE);
   glEnable(GL_DEPTH);
   glEnable(GL_RGB);
   
   m_pBitmap = BitmapHelper::LoadBitMap("splash.bmp");
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Black background
   m_width = m_pBitmap->ptrHeaderBitMapInfo.width;
   m_height = m_pBitmap->ptrHeaderBitMapInfo.height;
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glPixelStorei(GL_PACK_ALIGNMENT, 1);
   glBindTexture(GL_TEXTURE_2D, m_texture[0]);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m_width, m_height, 0, GL_BGR, GL_UNSIGNED_BYTE, (GLvoid*)m_pBitmap->pData);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
}

void GLWidget::paintGL()
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the window with current clearing color
   glShadeModel(GL_SMOOTH);
   glEnable(GL_NORMALIZE);
   glPushMatrix();
   {
      glDisable(GL_LIGHTING); // Draw plane that the cube rests on
      glEnable(GL_TEXTURE_2D); // should use shader, but for an example fixed pipeline is ok ;\)
      glBindTexture(GL_TEXTURE_2D, m_texture[0]);
      glBegin(GL_TRIANGLE_STRIP); // draw something with the texture on
      {
         glTexCoord2f(0.0, 0.0);
         glVertex2f(-1.0, -1.0);
         
         glTexCoord2f(1.0, 0.0);
         glVertex2f(1.0, -1.0);
         
         glTexCoord2f(0.0, 1.0);
         glVertex2f(-1.0, 1.0);
         
         glTexCoord2f(1.0, 1.0);
         glVertex2f(1.0, 1.0);
      }
      glEnd();
   }
   glPopMatrix();
   swapBuffers(); // Flush drawing commands
}






More information about the Qt-interest-old mailing list