As an exercise set to myself, I wanted to make a Mesh loader using modern OpenGL.

However, I have to ways of representing the notion of face of a mesh.

Currently, I am using what seems the most natural. A mesh contains a


and a Triangle is simply

struct Triangle
    unsigned int Vertices[3];

(i.e. each triangle stores the three indices of its vertices). NOTE : a mesh contains others things (such as the vertices and the normals but I didn't include them here for simplicity).

However, OpenGL require a different representation for using EBO : only one static array on indices (implicitly grouped by 3).

What I have come up with is a trade-off between these representations : once the mesh is loaded, I generate a static array of size

3 * mesh->Faces.size()

but I assume this is not the best option for memory use and redundancy.

So my questions are :

  • If I want to keep my current representation of a mesh (with a vector of faces), how should I set OpenGL to properly render such a mesh ? Is my current solution of generating a new static a good practice ?
  • Assuming I can use the representation I want for my mesh. What would you recommand and why ?

1 Answer 1


Actually your current way is fine.

C++ struct layout will let you turn the Triangle* into a int* and store that into the EBO.

  • \$\begingroup\$ Thanks ! And how should I turn properly turn the std::vector<Triangle> to my unsigned int* that OpenGL require ? \$\endgroup\$
    – Rivten
    Mar 29, 2016 at 15:20
  • \$\begingroup\$ vector has a data() function that'll return the Triangle* which you can cast to the int*. \$\endgroup\$ Mar 29, 2016 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .