Search code examples
c++openglpolygonwavefront

in a wavefront object file (.obj) how am i supposed to render faces with more than 4 vertices in opengl?


So using a Wavefront object file how am i supposed to render faces that have more than 4 vertices in OpenGL?

I understand that if it has 3 vertices I use GL_TRIANGLES, if it has 4 I use GL_QUADS, but if it has 5 or more, what am I supposed to use? Is there a standard?


Solution

  • OBJ exporters will export the vertices in a sane order for each face (anti-/clockwise), and long as your faces are coplanar and convex (which they bloody should be!) - you can use GL_TRIANGLE_FAN.

    I disagree with Nicol Bolas' point that faces should always have 3 vertices, although fool proof, if your polygons follow the above rules, using GL_TRIANGLE_FAN simplifies your code and reduces system memory consumption. Nothing will change GPU side as the polygons will be decomposed to triangles anyway.