DuckPuppy
DuckPuppy

Reputation: 163

glDrawElements causes Access Violation

I am getting several GLErrors i do not know what to make of them.

  1. GL_INVALID_ENUM
  2. GL_INVALID_ENUM
  3. GL_INVALID_OPERATION
  4. GL_INVALID_OPERATION

How do i go about debugging this ?

This is my Code:

    void MeshPNU::create(aiMesh* m) {

for (std::uint32_t i = 0; i < m->mNumVertices; i++) {
    vertexPNU v(m, i);
    vertices.push_back(v);
}
for (std::uint32_t i = 0; i < m->mNumFaces; i++) {
    for (std::uint32_t j = 0; j < m->mFaces[i].mNumIndices; j++) {
        indices.push_back(m->mFaces[i].mIndices[j]);
    }
}
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &IBO);

glBindBuffer(GL_VERTEX_ARRAY, VBO);
glBufferData(GL_VERTEX_ARRAY, vertices.size() * sizeof(vertexPNU), vertices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(std::uint32_t), indices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); 
glEnableVertexAttribArray(2);
}
void MeshPNU::draw() 
{
    glBindVertexArray(VAO);
    glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
}

enter image description here

Upvotes: 0

Views: 466

Answers (1)

Sedfer
Sedfer

Reputation: 61

glBindBuffer(GL_VERTEX_ARRAY, VBO); is not correct enum for VBO, you should use GL_ARRAY_BUFFER instead.

Please let me know, if it fixes your problem.

Upvotes: 1

Related Questions