Hi all, thanks for your time.
The code I use to initialize the vaos is:
glGenVertexArrays(1, &iVAO);
glBindVertexArray(iVAO);
glGenBuffers(5, m_Buffers);
//here I load the buffers' information and the images
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Bones[0]) * Bones.size(), &Bones[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size()*3, &Indices[0],
GL_STATIC_DRAW);
glBindVertexArray(0);
And the code to draw them is:
glBindVertexArray(iVAO);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
for (unsigned int i = 0 ; i < meshes.size() ; i++) {
const unsigned int MaterialIndex = meshes[i].MaterialIndex;
if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
}
glDrawElementsBaseVertex(GL_TRIANGLES,
meshes[i].NumIndices,
GL_UNSIGNED_INT,
(void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
meshes[i].BaseVertex);
}
// Make sure the VAO is not changed from the outside
glBindVertexArray(0);
And this way it works, but if the VAO weren't invalid It should work like this
glBindVertexArray(iVAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
for (unsigned int i = 0 ; i < meshes.size() ; i++) {
const unsigned int MaterialIndex = meshes[i].MaterialIndex;
if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
}
glDrawElementsBaseVertex(GL_TRIANGLES,
meshes[i].NumIndices,
GL_UNSIGNED_INT,
(void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
meshes[i].BaseVertex);
}
// Make sure the VAO is not changed from the outside
glBindVertexArray(0);