首页 > 解决方案 > Pyside2 - QOpenGLFunction 对象没有属性 glShaderSource

问题描述

我正在尝试使用QOpenGLFunctionswith PySide2。一切都很好,直到我尝试使用在实施中glShaderSource()似乎缺少的东西PySide2QOpenGLFunctions

AttributeError:“PySide2.QtGui.QOpenGLFunctions”对象没有属性“glShaderSource”

此外,https://doc.qt.io/qtforpython-5/PySide2/QtGui/QOpenGLFunctions.htmlglShaderSource中也缺少

不是很久没解决的bug吗?因为我使用的是 PySide5.12并且链接的文档是针对5.15. 有人用QOpenGLFunctionsPySide2?因为你如何在没有着色器的情况下使用它?


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)
            shader = f.glCreateShader(GL.GL_VERTEX_SHADER)
            f.glShaderSource(shader, "") # <-AttributeError
            f.glCompileShader(shader)
            ####

标签: pythonopenglpysidepyside2

解决方案


推荐阅读