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 
float * objectGeometry = scene.objects[k].verticesAsFloatArray();
glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, objectGeometry);

// normals
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);
  • $\begingroup$ Are you sure scene.objects[k].vertices.size() is the same size as the number of indices? $\endgroup$
    – Reynolds
    Commented Mar 8, 2018 at 11:09
  • $\begingroup$ @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 $\endgroup$ Commented Mar 8, 2018 at 13:51
  • $\begingroup$ The second arguments is the number of indices you want to read from your array indices. So it should be indices.size(). $\endgroup$
    – Reynolds
    Commented Mar 8, 2018 at 14:28
  • $\begingroup$ @Reynolds Oh my, thank you very much. I find openGL documentation very confusing. $\endgroup$ Commented Mar 8, 2018 at 14:33

1 Answer 1


glDrawElements specifies the second argument to be the number of elements to be taken from the buffer of indices, not the number of vertices. The correct number would be the number of triangles times three.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.