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)
添加回答
舉報