Python QOpenGLFunctions和PySide2
如何从Python QOpenGLFunctions和PySide2,python,opengl,pyside2,pyopengl,Python,Opengl,Pyside2,Pyopengl,如何从PySide2使用QOpenGLFunctions 问题在于GLEnum的问题,API文档中提到了GLEnum,但没有说明从哪里可以获得它 例如,我想调用glGetString(),我尝试: from OpenGL import GL from PySide2.QtGui import QOpenGLFunctions as GLF GLF.glGetString(GL.GL_VERSION)) 但它会产生一个错误 TypeError: descriptor 'glGetString'
PySide2
使用QOpenGLFunctions
问题在于GLEnum的问题,API文档中提到了GLEnum,但没有说明从哪里可以获得它
例如,我想调用glGetString(),
我尝试:
from OpenGL import GL
from PySide2.QtGui import QOpenGLFunctions as GLF
GLF.glGetString(GL.GL_VERSION))
但它会产生一个错误
TypeError: descriptor 'glGetString' requires a 'PySide2.QtGui.QOpenGLFunctions' object but received a 'IntConstant'
您必须使用与当前QOpenGLContext关联的QOpenGLFunctions,例如,您可以使用以下代码:
from OpenGL import GL
from PySide2 import QtGui
if __name__ == "__main__":
app = QtGui.QGuiApplication()
off_screen = QtGui.QOffscreenSurface()
off_screen.create()
if off_screen.isValid():
context = QtGui.QOpenGLContext()
if context.create():
context.makeCurrent(off_screen)
f = QtGui.QOpenGLFunctions(context)
print(f.glGetString(GL.GL_VERSION))
输出:
3.0 Mesa 20.1.6