Difference when enabling index buffer before and after GL_ARRAY_BUFFER

This topic is 832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all,

I tried to find this explanation in the books but could not find anything.

The problem.

When I turn on index buffer after GL_ARRAY_BUFFER. Everythings renders properly

	for (int i = 0; i < model.meshes.size(); i++)
{
MD5Mesh* m = &model.meshes[i];
m->UpdateMesh(m, jointFrame, nullptr, m->deformInfo);
deformInfo_t* vert = m->deformInfo;
drawVert* vertD = vert->verts;

glBindTexture(GL_TEXTURE_2D, tex_id[i]);
buffer[i].EnableVAO();
buffer[i].EnableVBO();

index[i].EnableVBO();

buffer[i].Update(vert->verts, sizeof(vertD[0]) * vert->numSourceVerts);
glDrawElements(GL_TRIANGLES, m->deformInfo->numIndexes, GL_UNSIGNED_INT, (void*)0);
}



[attachment=31408:Screenshot_41.png]

But when I enable index buffer before enabling GL_ARRAY_BUFFER. I get this

[attachment=31409:Screenshot_42.png]

Any ideas why it is like this?

Thanks.

Share on other sites

You should show how EnableVAO, EnableVBO and Update methods are implemented. And what is the code for failing render? Since you grouped VAO and vertex buffer lines together, I guess you just bound the index buffer before binding the VAO. Just remember that the VAO should be bound first, because the buffers are bound to it.

glBindVertexArray(vao);
glBindBuffer(...indexbuffer...);
glBindBuffer(...vertexbuffer...);

Share on other sites
Yes, the current GL_ELEMENT_ARRAY_BUFFER binding is part of the VAO state, so if you change the VAO you'll change that binding, which is most likely what's happening here.

Share on other sites

First test for an error code, maybe something is screwd up.

Secondly, VAO is created to be bound at first so all you have to do is bind the VAO and not all of the VBO's.

Only the first call to bindings should include the VBOS so openGL knows which buffers are bound to your array.

Lastly, It's easy to do something wrong when dealing with buffers, I'll need to know what kind of update you do in update()...

I might think it probably takes the wrong information. Again depends on how you arrange it.

Edited by WoopsASword

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631740
• Total Posts
3001962
×