我试着运行一个非常简单的OpenGL示例:
import sys
from OpenGL import GL as gl
from PyQt6.QtOpenGLWidgets import QOpenGLWidget
from PyQt6.QtWidgets import QApplication
class Widget(QOpenGLWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQt6, OpenGL 3.3")
self.resize(400, 400)
def initializeGL(self):
gl.glClearColor(0.5, 0.5, 0.5, 1)
def paintGL(self):
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec())
但我有一个错误:
Traceback (most recent call last):
File "main.py", line 16, in initializeGL
gl.glClearColor(0, 0, 0, 1)
File "E:ProgramFilesPythonPython38libsite-packagesOpenGLplatformbaseplatform.py", line 415, in __call__
return self( *args,**named )
File "E:ProgramFilesPythonPython38libsite-packagesOpenGLerror.py", line 230, in glCheckError
raise self._errorClass(
OpenGL.error.GLError: GLError(
err = 1282,
description = b'invalid operation',
baseOperation = glClearColor,
cArguments = (0, 0, 0, 1)
)
这是相同的示例,但在PyQt5中是有效的:
import sys
from OpenGL import GL as gl
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QOpenGLWidget
class Widget(QOpenGLWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQt5, OpenGL 3.3")
self.resize(400, 400)
def initializeGL(self):
gl.glClearColor(0.5, 0.5, 0.5, 1)
def paintGL(self):
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
if __name__ == "__main__":
QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
app = QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
有两点不同:
1.QOpenGLWidget迁移至PyQt6.QtOpenGLWidget
1.1.PyQt5示例中的行:QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
1条答案
按热度按时间up9lanfz1#
这一行:
应替换为:
这些更改也适用于PySide6:
1.OpenGL类已移至单独的PyQt6.QtOpenGL命名空间:
PyQt5:
PyQt6:
1.QOpenGLWidget类已移至PyQt6.QtOpenGLWidget命名空间:
PyQt5:
PyQt6:
1.更改了着色器类型的枚举:
PyQt5:
PyQt6:
1.已更改枚举目标纹理:
PyQt5:
PyQt6:
1.更改了设置纹理滤镜的枚举:
PyQt5:
PyQt6:
1.更改了WrapMode的枚举:
PyQt5:
PyQt6:
1.更改枚举以设置应用程序属性:
PyQt5:
PyQt6:
几个基本的非图形更改:
1.更改了文件打开模式的枚举:
PyQt5:
PyQt6:
1.QApplication.exec_()方法已重命名为QApplication.exec()
PyQt5:
PyQt6:
落地科拉达立方体与子弹物理,OpenGL 3.3:
您应该安装以下程序包: