如何在PySide2中使用QOpenGLFunctions
问题出在GLEnum上,API文档提到了它,但没有告诉人们可以从哪里得到它。
例如,我想调用glGetString(), I try:
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'发布于 2020-09-03 15:48:02
您必须使用与当前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.6https://stackoverflow.com/questions/63660860
复制相似问题