1 回答
TA贡献1712条经验 获得超3个赞
GL_COLOR_BUFFER_BIT
不是 的有效枚举常量glEnable
,但它是 的适当参数glClear
。在通过以下方式设置清晰颜色后
调用:glClear
glClearColor
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)
添加回答
举报