In the wavefront object file (.obj), how should I display faces with more than four vertices in opengl?

So, using the Wavefront object file, how should I draw 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 should I use? Is there a standard?

+7
source share
3 answers

OBJ exporters will export vertices in the correct order for each face (counterclockwise / clockwise) and as long as your faces are coplanar and convex (what should they be bloody!) - you can use GL_TRIANGLE_FAN.

I disagree with the point of Nikola Bolas that individuals should always have 3 vertices, although proof of a fool, if your polygons comply with the above rules, using GL_TRIANGLE_FAN simplifies your code and reduces system memory consumption. Nothing will change the side of the GPU, since the polygons will be laid out in triangles.

+7
source

First, you must specify any export tool so as not to export faces with so many vertices. Persons must have 3 peaks, period.

If your export tool cannot do this, then your loading tool should break the polygons into 3 vertices. I am sure the asset importer library can do this.

+8
source

In practice, most of the faces of the wavefront are coplanar and convex, but I can not find anything in the original OBJ specification stating that this is guaranteed.

If the face is coplanar and convex, you can use GL_TRIANGLE_FAN or GL_TRIANGLE and manually evaluate the fan. The fan has all the triangles dividing the first vertex. Like this:

 // manually generate a triangle-fan for (int x = 1; x < (faceIndicies.Length-1); x++) { renderIndicies.Add(faceIndicies[0]); renderIndicies.Add(faceIndicies[x]); renderIndicies.Add(faceIndicies[x+1]); } 

If the number of vertices in the n-gon is large, using GL_TRIANGLE_STRIP or manually creating your own triangle stripes can give better visual results. But this is very rare in wavefront OBJ files.

If the face is coplanar but concave, it is necessary to triangulate the face using an algorithm such as a method of cutting ears.

http://en.wikipedia.org/wiki/Polygon_triangulation#Ear_clipping_method

If the vertices are not coplanar, you are screwed because the OBJ does not store enough information to know what form of tessellation was intended.

+4
source

All Articles