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.
score:0
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
score:1
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_()
Credit To: stackoverflow.com
Related Query
- PyQt5 QWindow + PyOpenGL error 1282 'invalid operation' with every OpenGL function
- Error while Transforming the Object using PyOpenGL with PyQt5
- PyOpenGL multitexture error - invalid operation
- Invalid syntax error using format with a string in Python 3 and Matplotlib
- PyQt5 error "PyCapsule_GetPointer called with incorrect name"
- Can not submit a form with robobrowser. Invalid submit error
- Problems with openGL and PyQt5
- What wrong is in my code that the error keeps on increasing with every iteration of gradient descent?
- Python error with request post : 'Connection aborted, timeout('The write operation timed out')
- Invalid file error when trying to open file in PyQT5
- invalid literal for int() with base 10: '' error
- Tensorflow build from source error ValueError: invalid literal for int() with base 10: '' during cuda path configuration?
- Httplib2 invalid syntax error with [python3.6]
- I keep getting the following error when I try to take in user input - ValueError: invalid literal for int() with base 10: ''
- error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
- Syntax error on print with Python 3
- Yum crashed with Keyboard Interrupt error
- ValueError: invalid literal for int () with base 10
- Getting error with pip search and pip install
- Error when creating a new text file with python?
- Error when checking target: expected dense_3 to have shape (3,) but got array with shape (1,)
- python 3 try-except all with error
- Is 'encoding is an invalid keyword' error inevitable in python 2.x?
- Unicode error handling with Python 3's readlines()
- ImportError: with error 'is not a package'
- Python sockets error TypeError: a bytes-like object is required, not 'str' with send function
- Invalid Syntax error when running python from inside Visual Studio Code
- Invalid Python SDK Error while using python 3.4 on PyCharm
- Make every fields as optional with Pydantic
- sqlite3 error on AWS lambda with Python 3
- SKLearn 0.20.2 - Import error with RandomizedPCA?
- cython error compiling with print function parameters
- Why am I suddenly getting a no attribute 'CLSIDToPackageMap' error with win32com.client?
- Python: Module Error with pprint, no error with print
- 1006 Connection closed abnormally error with python 3.7 websockets
- Python3.4: Opening file with mode 'w' still gives me FileNotFound error
- print syntax error with python 3
- How to fix invalid syntax error at 'except ValueError'?
- Cannot install pyodbc in docker and getting error command 'gcc' failed with exit status 1
- How to deal with Kivy installing error in Python 3.8?
- Anaconda3 2.4 with python 3.5 installation error (procedure entry not found; Windows 10)
- SSL Connection Error while using MySQL Connector with Python
- Getting Error 403 in Google Colab with Tensorboard with Firefox
- Current Screen Size in Python3 with PyQt5
- 500 error with urllib.request.urlopen
- py2app builds ok but app fails with "_tkinter.TclError" (and no error message!)
- configure returned code 256 - python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/lxml
- Error in anyjson setup command: use_2to3 is invalid
- Python can't install Box2D swig.exe failed with error code 1
- Why am I getting this error in scrapy - python3.7 invalid syntax
More Query from same tag
- How would I read the outputs with angle brackets in python
- How to use PyMC (v4.0.1) with statsmodels to estimate state space models?
- Remove stop words in text file without NLTK
- Python unittest + asyncio hangs forever
- Zipping a product of iterators and a count iterator
- How to download multiple files using Python 3.7
- How to process Row number window function on incremental data
- Unable to build opencv-python with python 3.8
- Normalization - Signal with different sampling rates
- Why Redhat does not include python 3 in centos 7?
- Why does my for-loop not work properly in Python?
- How to dynamically access object attributes in python without boxing?
- Can't create s3 resource/client in boto3
- Microstepping for Steppermotor Z-axis
- ImportError: No module named PyQt5.QtWidgets
- failed API call - error 400
- Unable to parse AWS DynamoDB binary get item in boto3 python
- Incompatible shapes: [217,1] vs. [480,1]
- TypeError: descriptor 'date' for 'datetime.datetime' objects doesn't apply to a 'int' object
- Python gcd with negative numbers
- How to append first item of each list to a new list with equal probability
- Python RegEx match results are too minimal, please advise
- How to return non-empty top row column values of unknown column length in Excel?
- How accelerate an algorithm to find the time overlaps?
- How do I import all functions from a package in python?
- How can I create a list of R=10000 booleans called inside in Python?
- Can I get an item from a PriorityQueue without removing it yet?
- Dictionary Comprehension with multiple statements
- Read generated excel sheet from pivot table show details option using python
- How to configure JSON for graphql query?
- Does mypy only type check a function if it declares a return type?
- Subprocess run/call not working
- Got SyntaxError around self.async while import KafkaProducer on python 3.8.5 on mac
- Configure Komodo Edit for Python 3.2
- gensim Generating LSI model causes "Python has stopped working"