From c3752cee9ca8648d49e29e5cd519d158abd1d262 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Fri, 28 Jan 2011 20:33:46 -0200 Subject: Fixed example to avoid segfault on Windows due to incorrect call to bindTexture method. Code ported to new signal/slots. Fixed routines to free OpenGL resources. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Renato Araújo Marcelo Lira --- examples/opengl/textures/textures.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'examples/opengl') diff --git a/examples/opengl/textures/textures.py b/examples/opengl/textures/textures.py index 29a0425..72ab041 100755 --- a/examples/opengl/textures/textures.py +++ b/examples/opengl/textures/textures.py @@ -52,6 +52,8 @@ class GLWidget(QtOpenGL.QGLWidget): ( ( -1, -1, +1 ), ( +1, -1, +1 ), ( +1, +1, +1 ), ( -1, +1, +1 ) ) ) + clicked = QtCore.Signal() + def __init__(self, parent, shareWidget): QtOpenGL.QGLWidget.__init__(self, parent, shareWidget) @@ -62,12 +64,9 @@ class GLWidget(QtOpenGL.QGLWidget): self.clearColor = QtGui.QColor() self.lastPos = QtCore.QPoint() - def __del__(self): - # For some reason, GLWidget is defined to be None when this is - # called. We access the class variables via the instance's __class__ - # attribute. - self.__class__.refCount -= 1 - if self.__class__.refCount == 0: + def freeGLResources(self): + GLWidget.refCount -= 1 + if GLWidget.refCount == 0: self.makeCurrent() glDeleteLists(self.__class__.sharedObject, 1) @@ -89,6 +88,9 @@ class GLWidget(QtOpenGL.QGLWidget): def initializeGL(self): if not GLWidget.sharedObject: + self.textures = [] + for i in range(6): + self.textures.append(self.bindTexture(QtGui.QPixmap(":/images/side%d.png" % (i + 1)))) GLWidget.sharedObject = self.makeObject() GLWidget.refCount += 1 @@ -130,14 +132,14 @@ class GLWidget(QtOpenGL.QGLWidget): self.lastPos = QtCore.QPoint(event.pos()) def mouseReleaseEvent(self, event): - self.emit(QtCore.SIGNAL("clicked()")) + self.clicked.emit() def makeObject(self): dlist = glGenLists(1) glNewList(dlist, GL_COMPILE) for i in range(6): - self.bindTexture(QtGui.QPixmap(":/images/side%d.png" % (i + 1))) + glBindTexture(GL_TEXTURE_2D, self.textures[i]) glBegin(GL_QUADS) for j in range(4): @@ -181,15 +183,15 @@ class Window(QtGui.QWidget): self.glWidgets[i][j].rotateBy(+42 * 16, +42 * 16, -21 * 16) mainLayout.addWidget(self.glWidgets[i][j], i, j) - self.connect(self.glWidgets[i][j], QtCore.SIGNAL("clicked()"), - self.setCurrentGlWidget) + self.glWidgets[i][j].clicked.connect(self.setCurrentGlWidget) + QtGui.qApp.lastWindowClosed.connect(self.glWidgets[i][j].freeGLResources) self.setLayout(mainLayout) self.currentGlWidget = self.glWidgets[0][0] timer = QtCore.QTimer(self) - self.connect(timer, QtCore.SIGNAL("timeout()"), self.rotateOneStep) + timer.timeout.connect(self.rotateOneStep) timer.start(20) self.setWindowTitle(self.tr("Textures")) -- cgit v1.2.3