glDrawElements 抛出错误代码 GL_INVALID_ENUM (0x500)
glDrawElements throws error code GL_INVALID_ENUM (0x500)
我尝试使用 OpenGL 和索引绘制带纹理的正方形。首先,我使用 VAO 和 VBO 绘制了一个简单的白色正方形。之后,我尝试创建一个索引缓冲区对象来绘制相同的简单白色方块,但它没有绘制任何东西并且抛出错误 core GL_INVALID_ENUM
(0x500)。调用 glDrawElements
.
后抛出此错误代码
这里有我的部分代码:
创建索引缓冲区对象、VAO 和 VBO 的函数:
void Object::loadObject(const float *lpfVertices, size_t uVerticesSize, const char *lpbElementsList, size_t uNumElements) {
this->uNumElements = uNumElements;
glGenVertexArrays(1, &uVertexArrayID);
glBindVertexArray(uVertexArrayID);
glGenBuffers(1, &uVertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, uVertexBufferID);
glBufferData(GL_ARRAY_BUFFER, uVerticesSize, (void *)lpfVertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, NULL);
glEnableVertexAttribArray(0);
glGenBuffers(1, &uElemetsListID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, uElemetsListID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, uNumElements, lpbElementsList, GL_STATIC_DRAW);
}
渲染我的对象的函数:
void Object::renderObject() {
glBindVertexArray(uVertexArrayID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, uElemetsListID);
glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
}
部分主要代码:
object.loadObject(lpfTriangleVertices, sizeof(lpfTriangleVertices), lpbElementsList, sizeof(lpbElementsList));
uProgID = loadShader("default.vs", "default.fs");
while(!glfwWindowShouldClose(lpstWndID)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(uProgID);
object.renderObject();
glfwSwapBuffers(lpstWndID);
}
glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
^^^^^^^
GL_BYTE
不是 glDrawElements()
中 type
的有效参数:
type
Specifies the type of the values in indices
. Must be one of GL_UNSIGNED_BYTE
, GL_UNSIGNED_SHORT
, or GL_UNSIGNED_INT
.
我尝试使用 OpenGL 和索引绘制带纹理的正方形。首先,我使用 VAO 和 VBO 绘制了一个简单的白色正方形。之后,我尝试创建一个索引缓冲区对象来绘制相同的简单白色方块,但它没有绘制任何东西并且抛出错误 core GL_INVALID_ENUM
(0x500)。调用 glDrawElements
.
这里有我的部分代码:
创建索引缓冲区对象、VAO 和 VBO 的函数:
void Object::loadObject(const float *lpfVertices, size_t uVerticesSize, const char *lpbElementsList, size_t uNumElements) {
this->uNumElements = uNumElements;
glGenVertexArrays(1, &uVertexArrayID);
glBindVertexArray(uVertexArrayID);
glGenBuffers(1, &uVertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, uVertexBufferID);
glBufferData(GL_ARRAY_BUFFER, uVerticesSize, (void *)lpfVertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, NULL);
glEnableVertexAttribArray(0);
glGenBuffers(1, &uElemetsListID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, uElemetsListID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, uNumElements, lpbElementsList, GL_STATIC_DRAW);
}
渲染我的对象的函数:
void Object::renderObject() {
glBindVertexArray(uVertexArrayID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, uElemetsListID);
glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
}
部分主要代码:
object.loadObject(lpfTriangleVertices, sizeof(lpfTriangleVertices), lpbElementsList, sizeof(lpbElementsList));
uProgID = loadShader("default.vs", "default.fs");
while(!glfwWindowShouldClose(lpstWndID)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(uProgID);
object.renderObject();
glfwSwapBuffers(lpstWndID);
}
glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
^^^^^^^
GL_BYTE
不是 glDrawElements()
中 type
的有效参数:
type
Specifies the type of the values in
indices
. Must be one ofGL_UNSIGNED_BYTE
,GL_UNSIGNED_SHORT
, orGL_UNSIGNED_INT
.