为了账号安全,请及时绑定邮箱和手机立即绑定

使用自定义 QSurfaceFormat 时出现 PySide2 OpenGL 错误

使用自定义 QSurfaceFormat 时出现 PySide2 OpenGL 错误

莫回无 2023-06-06 16:35:18
我正在使用QSurfaceFormat明确定义OpenGL Core 配置文件并设置次要/主要版本。问题是,自定义表面格式的分配给我以下错误:Traceback (most recent call last):  File "/home/artem/PycharmProjects/PolyEdit3D/PolyEdit3D/Widgets/PlyViewport.py", line 22, in initializeGL    gl.glEnable(gl.GL_COLOR_BUFFER_BIT)  File "/home/artem/.local/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 415, in __call__    return self( *args, **named )  File "src/errorchecker.pyx", line 58, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckErrorOpenGL.error.GLError: GLError(    err = 1280,    description = b'invalid enumerant',    baseOperation = glEnable,    cArguments = (GL_COLOR_BUFFER_BIT,))Traceback (most recent call last):  File "/home/artem/PycharmProjects/PolyEdit3D/PolyEdit3D/Widgets/PlyViewport.py", line 69, in paintGL    gl.glDrawElements(gl.GL_TRIANGLES, 6, gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))  File "src/latebind.pyx", line 39, in OpenGL_accelerate.latebind.LateBind.__call__  File "src/wrapper.pyx", line 318, in OpenGL_accelerate.wrapper.Wrapper.__call__  File "src/wrapper.pyx", line 311, in OpenGL_accelerate.wrapper.Wrapper.__call__  File "/home/artem/.local/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 415, in __call__    return self( *args, **named )  File "src/errorchecker.pyx", line 58, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckErrorOpenGL.error.GLError: GLError(    err = 1282,    description = b'invalid operation',    baseOperation = glDrawElements,    pyArgs = (        GL_TRIANGLES,        6,        GL_UNSIGNED_INT,        c_void_p(None),    ),    cArgs = (        GL_TRIANGLES,        6,        GL_UNSIGNED_INT,        c_void_p(None),    ),    cArguments = (        GL_TRIANGLES,        6,        GL_UNSIGNED_INT,        c_void_p(None),    ))正如您所看到的,还有gl.glEnable(gl.GL_COLOR_BUFFER_BIT)其他一些简单的错误。没有指定QSurfaceFormat一切都像一个魅力。
查看完整描述

1 回答

?
交互式爱情

TA贡献1712条经验 获得超3个赞

GL_COLOR_BUFFER_BIT不是 的有效枚举常量glEnable,但它是 的适当参数glClear。在通过以下方式设置清晰颜色后
调用:glClearglClearColor

class PlyViewportWidget(QtWidgets.QOpenGLWidget):

    # [...]


    def initializeGL(self):

        

        #gl.glEnable(gl.GL_COLOR_BUFFER_BIT) <---- DELETE

        

        gl.glClearColor(0.4, 0.4, 0.4, 1)


        gl.glClear(gl.GL_COLOR_BUFFER_BIT) # <---- ADD

您错过了创建命名顶点数组对象的机会:

class PlyViewportWidget(QtWidgets.QOpenGLWidget):

    # [...]


    def initializeGL(self):

        # [...]


        self.vao = gl.glGenVertexArrays(1) # <--- 

        gl.glBindVertexArray(self.vao)     # <--- 


        self.vbo = gl.glGenBuffers(1)

        self.ebo = gl.glGenBuffers(1)


        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo)

        gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices, gl.GL_STATIC_DRAW)


        gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self.ebo)

        gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indices.nbytes, indices, gl.GL_STATIC_DRAW)


        gl.glEnableVertexAttribArray(0)

        gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 3 * ctypes.sizeof(ctypes.c_float), ctypes.c_void_p(0))


        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)

        gl.glBindVertexArray(0)


查看完整回答
反对 回复 2023-06-06
  • 1 回答
  • 0 关注
  • 133 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信