Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I've run out of ideas and I need some help. Consider the following snippet (modified
http://www.riverbankcomputing.com/pipermail/pyqt/2014-July/034542.html
):
from OpenGL import GL
from PyQt5 import Qt
class GLWindow(Qt.QWindow):
def __init__(self):
super().__init__()
self.setSurfaceType(Qt.QWindow.OpenGLSurface)
self.context = Qt.QOpenGLContext()
self.context.setFormat(self.requestedFormat())
if not self.context.create():
raise Exception('self.context.create() failed')
self.create()
def exposeEvent(self, ev):
ev.accept()
if self.isExposed() and self.isVisible():
self.update()
def update(self):
self.context.makeCurrent(self)
GL.glClearColor(1.0, 0.0, 0.0, 0.0)
GL.glClearDepth(1)
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
GL.glFlush()
self.context.swapBuffers(self)
app = Qt.QApplication([])
win = GLWindow()
widget = Qt.QWidget.createWindowContainer(win, None, Qt.Qt.Widget)
widget.show()
app.exec_()
No matter what OpenGL functions I call after makeCurrent(), they raise the following exception:
File "errorchecker.pyx", line 53, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError (src\errorchecker.c:1218)
OpenGL.error.GLError: GLError(
err = 1282,
description = b'nieprawid\xb3owa operacja',
baseOperation = glClearColor,
cArguments = (1.0, 0.0, 0.0, 0.0)
Besides, none of PyQt5 OpenGL examples, except openglwindow.py, work.
I'm using Python 3.4.2 win32, PyQt5 5.3.2 and PyOpenGL 3.1.0. Any ideas? I've found that PyQt5 binary was probably built against OpenGL ES, but I don't know if that matters when using PyOpenGL calls.
–
–
You should use QtOpenGL.QGLWidget
. The Qt.QWindow
is not using OpenGL.
Here is a working example:
import struct
from PyQt5 import QtOpenGL, QtWidgets
import ModernGL
class QGLControllerWidget(QtOpenGL.QGLWidget):
def __init__(self):
fmt = QtOpenGL.QGLFormat()
fmt.setVersion(3, 3)
fmt.setProfile(QtOpenGL.QGLFormat.CoreProfile)
fmt.setSampleBuffers(True)
super(QGLControllerWidget, self).__init__(fmt, None)
def initializeGL(self):
self.ctx = ModernGL.create_context()
prog = self.ctx.program([
self.ctx.vertex_shader('''
#version 330
in vec2 vert;
void main() {
gl_Position = vec4(vert, 0.0, 1.0);
'''),
self.ctx.fragment_shader('''
#version 330
out vec4 color;
void main() {
color = vec4(0.30, 0.50, 1.00, 1.0);
'''),
vbo = self.ctx.buffer(struct.pack('6f', 0.0, 0.8, -0.6, -0.8, 0.6, -0.8))
self.vao = self.ctx.simple_vertex_array(prog, vbo, ['vert'])
def paintGL(self):
self.ctx.viewport = (0, 0, self.width(), self.height())
self.ctx.clear(0.9, 0.9, 0.9)
self.vao.render()
self.ctx.finish()
app = QtWidgets.QApplication([])
window = QGLControllerWidget()
window.move(QtWidgets.QDesktopWidget().rect().center() - window.rect().center())
window.show()
app.exec_()
I can only offer a workaround.
I can reproduce the problem on windows too. the glClearColor
call is not the problem. The error occurs in context.create()
or self.create()
but pyOpenGL only notices it when it checks for errors after the first call.
I don't know what actually causes the problem, but if I just ignore the error it works just fine. At the end of __init__
I add:
self.context.makeCurrent(self)
GL.glGetError() # Ignore openGL error if one occured
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.