[PyQt] QGLWidget.renderText problem

V. Armando Sole sole at esrf.fr
Fri Sep 12 11:12:02 BST 2008


Hello,

QGLWidget.renderText gives me an OpenGL error for Qt versions >= 4.3.0 that 
prevents any further OpenGL output.

The example below works for Qt 4.2.3 but not above 4.3.0 (The second 
message is not shown).

My platform is windows and I am using PyOpenGL-3.0.0b5

Have you managed to use QGLWidget.renderText with Qt versions above 4.3.0?

Is there a work around?

Thanks,

Armando

import PyQt4.Qt as qt

try:
     import OpenGL.GL  as GL
except ImportError:
     raise ImportError, "OpenGL must be installed to use these functionalities"


class MyGLWidget(qt.QGLWidget):
     def __init__(self, parent = None):
         qt.QGLWidget.__init__(self, parent)
         self.xsize = 512
         self.ysize = 512

     def initializeGL(self):
         GL.glClearDepth(1.0)
         GL.glClearColor(0.5, 0.5, 0.5, 1.0)

         GL.glEnable(GL.GL_BLEND)
         GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

         GL.glShadeModel(GL.GL_FLAT)
         GL.glDisable(GL.GL_DITHER)
         GL.glMatrixMode(GL.GL_MODELVIEW)
         GL.glDisable(GL.GL_CULL_FACE)

     def resizeGL(self, width, height):
         GL.glViewport(0, 0, width, height)
         GL.glMatrixMode(GL.GL_PROJECTION)
         GL.glLoadIdentity()
         GL.glOrtho(0., 512., 0., 512., -self.xsize*self.ysize, 
self.xsize*self.ysize)
         GL.glMatrixMode(GL.GL_MODELVIEW)
         GL.glLoadIdentity()
         self.updateGL()


     def paintGL(self):
         GL.glClearColor(0.5, 0.5, 0.5, 1.0)
         GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
         GL.glMatrixMode(GL.GL_MODELVIEW)
         GL.glLoadIdentity()
         text = "You should see a white triangle below AND a message"
         GL.glColor3f(1., 1., 1.)
         self.renderText(230, 400, 0, text,self.font())
         GL.glBegin(GL.GL_TRIANGLES)
         GL.glVertex3f(200., 200., 0)
         GL.glVertex3f(300., 300., 0)
         GL.glVertex3f(400., 200., 0)
         GL.glEnd()
         self.renderText(256, 100, 0, "Congrats. It is working",self.font())

if __name__ == "__main__":
     app = qt.QApplication([])
     window = MyGLWidget()
     window.show()
     app.exec_()




More information about the PyQt mailing list