【问题标题】:QOpenGLFunctions and PySide2QOpenGLFunctions 和 PySide2
【发布时间】:2020-08-30 18:34:19
【问题描述】:

如何从PySide2使用QOpenGLFunctions

问题在于GLEnum,API 文档中提到了它,但没有说明可以从哪里获取它。

比如我想打电话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'

【问题讨论】:

    标签: python opengl pyside2 pyopengl


    【解决方案1】:

    您必须使用与当前 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多