Thread: [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 |
From: Ian M. <geo...@gm...> - 2009-10-15 23:21:48
|
I can't really help you directly, as I have no idea what PyQt4 is. The flickering screen might be caused by vsync issues and/or double/single buffering issues. To your second question, OpenGL also has many blending modes, so you can use those. I don't know how that works with PyQt4. Ian |
From: Frédéric <fre...@gb...> - 2009-10-16 06:12:50
|
On vendredi 16 octobre 2009, Ian Mallett wrote: > I can't really help you directly, as I have no idea what PyQt4 is. > > The flickering screen might be caused by vsync issues and/or > double/single buffering issues. > > To your second question, OpenGL also has many blending modes, so you can > use those. I don't know how that works with PyQt4. Thanks for your answer. I will dig for that vsync/double buffering issue. PyQt4 is the Python binding for the Qt graphical toolkit. -- Frédéric http://www.gbiloba.org |
From: Mads I. <mp...@co...> - 2009-10-16 08:08:54
|
Frédéric wrote: > On vendredi 16 octobre 2009, Ian Mallett wrote: > > >> I can't really help you directly, as I have no idea what PyQt4 is. >> >> The flickering screen might be caused by vsync issues and/or >> double/single buffering issues. >> >> To your second question, OpenGL also has many blending modes, so you can >> use those. I don't know how that works with PyQt4. >> > > Thanks for your answer. I will dig for that vsync/double buffering issue. > > PyQt4 is the Python binding for the Qt graphical toolkit. > > The QGLWidget from PyQt4 provides a generic framework for doing OpenGL graphics. But if you have PyQt4 related questions you should consult the PyQt4 mailing list: http://www.riverbankcomputing.co.uk/support/lists. The double buffering behavior of the QGLWidget, however, is pretty well-described in the Qt documentation http://doc.trolltech.com/4.5/qglwidget.html. In general, I suggest you start off by developing a very simple example that displays, say, a sphere or a torus and make sure this works as intended. Then, you can start off by doing more complex things. Best regards, Mads -- +-------------------------------------------------------------+ | Mads Ipsen, Scientific developer | +-------------------------------+-----------------------------+ | QuantumWise A/S | phone: +45-29716388 | | Nørre Søgade 27A | www: www.quantumwise.com | | DK-1370 Copenhagen K, Denmark | email: mp...@qu... | +-------------------------------+-----------------------------+ |
From: Frédéric <fre...@gb...> - 2009-10-16 08:29:51
|
Le vendredi 16 octobre 2009 08:08, Mads Ipsen a écrit : > The QGLWidget from PyQt4 provides a generic framework for doing OpenGL > graphics. But if you have PyQt4 related questions you should consult the > PyQt4 mailing list: http://www.riverbankcomputing.co.uk/support/lists. Sure; for this PyQt4 specific problem, I won't bother you here. But I really plan to use native OpenGL functions inside PyQt4 widget, so I need your help. Qt Widget and OpenGL have to work together, and it is not very easy to mix both worlds! > The double buffering behavior of the QGLWidget, however, is pretty > well-described in the Qt documentation > http://doc.trolltech.com/4.5/qglwidget.html. Thanks. > In general, I suggest you start off by developing a very simple example > that displays, say, a sphere or a torus and make sure this works as > intended. Then, you can start off by doing more complex things. Ok. -- Frédéric http://www.gbiloba.org |