GlDrawElements gives error code GL_INVALID_ENUM (0x500)

I tried to draw a textured square using OpenGL and indices. I first draw a simple white square using VAO and VBOs. After that I tried to create an index buffer object to draw the same simple white square, but it doesn't draw anything and it throws an error kernel GL_INVALID_ENUM

(0x500). This error code is called after the call glDrawElements

.

There are some parts of my code here:

The function that creates the index buffer object, VAO and 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);
}

      

The function that displays my object:

void Object::renderObject() {
    glBindVertexArray(uVertexArrayID);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, uElemetsListID);
    glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
}

      

Part of the main code:

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);
}

      

+3


source to share


1 answer


glDrawElements(GL_TRIANGLES, uNumElements, GL_BYTE, NULL);
                                           ^^^^^^^

      

GL_BYTE

is not a valid argument for type

in glDrawElements()

:



type

Defines the type of values ​​in indices

. Must be one of GL_UNSIGNED_BYTE

, GL_UNSIGNED_SHORT

or GL_UNSIGNED_INT

.

+5


source







All Articles