[PyQt] QOpenGLWindow (PyQt-5.4)
Trent Huong
aussie.dnb at gmail.com
Sat Jan 10 04:30:22 GMT 2015
Just a quick follow up, I've tried playing around with it some more. For
example, I've requested a specific OpenGL version and used
"versionFunctions" to get access to the OpenGL functions. However, this
gives new errors, this time:
"ImportError: No module named 'PyQt5._QOpenGLFunctions_4_2_Core'"
Is this just a case of user error or is the support for the new OpenGL
features still incomplete?
import os
import sys
from PyQt5.QtGui import (QOpenGLContext, QOpenGLWindow, QSurfaceFormat)
from PyQt5.QtWidgets import (QApplication,)
class MainWindow(QOpenGLWindow):
def initializeGL(self):
self.gl = self.context().versionFunctions()
#QOpenGLContext.currentContext().versionFunctions()
self.gl.initializeOpenGLFunctions()
self.gl.glClearColor(1.0, 0.0, 0.0, 1.0)
def resizeGL(self, w, h):
pass
def paintGL(self):
self.gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
if __name__ == '__main__':
app = QApplication(sys.argv)
format = QSurfaceFormat()
format.setVersion(4, 2)
format.setProfile(QSurfaceFormat.CoreProfile)
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSamples(4)
window = MainWindow()
window.setTitle("Hello OpenGL")
window.setFormat(format)
window.resize(640, 480)
window.show()
sys.exit(app.exec_())
Cheers,
T.H.
On Fri, Jan 9, 2015 at 4:34 PM, Trent Huong <aussie.dnb at gmail.com> wrote:
> Hi,
>
> I am running into some problems trying to use the new QOpenGLWindow in
> Qt-5.4. The error is "AttributeError: 'QOpenGLContext' object has no
> attribute 'functions'". However, according to the documentation,
> QOpenGLContext should have such a function. Are the bindings not up to date
> or have I made another mistake? Here is the code:
>
> import os
> import sys
>
> from PyQt5.QtGui import (QOpenGLWindow, QSurfaceFormat)
> from PyQt5.QtWidgets import (QApplication,)
>
> class MainWindow(QOpenGLWindow):
> def resizeGL(self, w, h):
> pass
> def paintGL(self):
> gl = self.context().functions()
>
> gl.glClearColor(1.0, 0.0, 0.0, 1.0)
> gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
>
> if __name__ == '__main__':
> app = QApplication(sys.argv)
>
> format = QSurfaceFormat()
> format.setDepthBufferSize(24);
> format.setStencilBufferSize(8);
> format.setSamples(4)
>
> window = MainWindow()
> window.setTitle("Hello OpenGL")
> window.setFormat(format)
> window.resize(640, 480)
> window.show()
>
> sys.exit(app.exec_())
>
> Thanks!
> T.H.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150110/c39cc662/attachment-0001.html>
More information about the PyQt
mailing list