# What is wrong with my glDrawElement code

I am reading a model from an obj file and draw it using glDrawElements. For some reasons, only a small part of it is drawn, even though I dont even have back-face culling turned on.

// vertices
glEnableVertexAttribArray(0);
float * objectGeometry = scene.objects[k].verticesAsFloatArray();
glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, objectGeometry);

// normals
glEnableVertexAttribArray(1);
float * objectNormals = scene.objects[k].normalsAsFloatArray();
glVertexAttribPointer(1, 3, GL_FLOAT, 0, 0, objectNormals);

// indices
int * indices = scene.objects[k].facesAsIndiceArray();
glDrawElements(GL_TRIANGLES, scene.objects[k].vertices.size(), GL_UNSIGNED_INT, indices);

• Are you sure scene.objects[k].vertices.size() is the same size as the number of indices? Mar 8 '18 at 11:09
• @Reynolds No, it doesn't. But I thought the whole point of having indices is that you dont need to duplicate vertices? Because one vertices could belong to many triangles Mar 8 '18 at 13:51
• The second arguments is the number of indices you want to read from your array indices. So it should be indices.size(). Mar 8 '18 at 14:28
• @Reynolds Oh my, thank you very much. I find openGL documentation very confusing. Mar 8 '18 at 14:33