11
votes

In order to create a VBO in OpenGl, I need to convert polygons to triangles. Is there an example of script/code somewhere that would describe this ? I would need something robust for convex and concave polygons.

3
I untagged this [cocoa] and tagged it [c] because I don't think it's a Cocoa question (or even an Objective-C question). - paulmelnikow
for those of you who need an implementation and not a pdf or description: github.com/mapbox/earcut - viggity

3 Answers

14
votes

Ear clipping is by far the best way to do this.

It is fully robust for both convex and concave polygons and runs in O(n^2) time

6
votes

Implement Chazelle's method. Triangulation in linear time! What's not to like? :)

More realistically, poly2tri.

0
votes

GLU tesselators provide a flexible way to do this.