[PyOpenGL-Users] Crossfade images
Brought to you by:
mcfletch
From: Frédéric <fre...@gb...> - 2009-10-15 14:22:05
|
Hi, I'm new to OpenGL, and I need your help to start a project: an open-source cross-platform photo slideshow software, like Pictures-To-Exe[1], ProShow[2] or m.objects[3]. It will probably be a mix of their main features. I started to write the engine, using PyQt4, which has nice features for both audio and display. Here is the part of the code I currently use to draw the images with their respective luminosity, to simulate the projectors: class PreviewDialogObject(QtGui.QWidget): def __init__(self, projectors): QtGui.QWidget.__init__(self) self.__projectors = projectors layout = QtGui.QHBoxLayout() self.__previewLabel = QtGui.QLabel("Preview") layout.addWidget(self.__previewLabel) self.setLayout(layout) self.resize(WIDTH, HEIGHT) def refresh(self): image = QtGui.QImage(WIDTH, HEIGHT, QtGui.QImage.Format_ARGB32_Premultiplied) painter = QtGui.QPainter(image) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source) painter.fillRect(QtCore.QRect(0, 0, WIDTH, HEIGHT), QtCore.Qt.black) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Screen) for d in self.__projectors.itervalues(): painter.setOpacity(d['opacity']) painter.drawImage((WIDTH - d['image'].width()) / 2, (HEIGHT - d['image'].height()) / 2, d['image']) painter.end() self.__previewLabel.setPixmap(QtGui.QPixmap.fromImage(image)) But even on my fast machine (quad core Q6600), I get some flickering ; so I think I need to switch to OpenGL to get very smooth transitions. I found some code on the web to use a QGLWidget, instead of the QWidget: class PreviewDialogGLObject(QtGui.QGraphicsView): def __init__(self, projectors): QtGui.QGraphicsView.__init__(self) self.__projectors = projectors format = QtOpenGL.QGLFormat() format.setSampleBuffers(True) format.setDoubleBuffer(True) widget = QtOpenGL.QGLWidget(format) self.setViewport(widget) self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate) self.__previewScene = PreviewScene(self.__projectors) self.setScene(self.__previewScene) self.resize(WIDTH, HEIGHT) def refresh(self): self.__previewScene.update() class PreviewScene(QtGui.QGraphicsScene): def __init__(self, projectors): QtGui.QGraphicsScene.__init__(self) self.__projectors = projectors def drawBackground(self, painter, rect): painter.save() painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source) painter.fillRect(QtCore.QRect(-WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT), QtCore.Qt.black) #painter.setCompositionMode(QtGui.QPainter.CompositionMode_Screen) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source) for d in self.__projectors.itervalues(): painter.setOpacity(d['opacity']) painter.drawImage(-d['image'].width() / 2, -d['image'].height() / 2, d['image']) painter.restore() But it does not improve anything at all! I get the same issue. The only difference is that I can't use the 'Screen' composition mode anymore :o/ This is why I'm here! I guess that I have to use native OpenGL functions in the drawBackground() method, to crossfade my images. But I can't get it work. I spent days on the web looking at tutorials or books, but I'm lost. I understand that I need to use textures, but all tutorials use different methods, and my tests does not lead to anything usable (it takes several seconds to refresh a simple image!). More, I think I should start using OpenGL3, but all functions used in the tutorials are deprecated, and I didn't find any information for replacement. So, it would be nice if someone could help me to start, with bases. I also would like to know if OpenGL will allow me to use complex composition modes, like 'screen' or 'addition', to simulate different projection results? Thanks for reading, [1] http://www.wnsoft.com/apr/index.html [2] http://www.photodex.com/products/proshowgold [3] http://www.mobjects.com -- Frédéric http://www.gbiloba.org |