The Problem
OpenGL and other low-level rendering APIs are limited to rendering convex polygons. This causes a complications to arise when trying to render concave primitives. In my case, I wanted to be able to render arbitrary 2D "ground," and not succumb to manually breaking apart the polygon into OpenGL-compatible primitives. Thus the search for a triangulation algorithm arose. All I could find were algorithm names without accompanying implementations or explanations, and long mathematical abstracts on computational geometry. Any implementations I
did find seemed to be extremely over-engineered and over-complicated for easy comprehension and adaptation. I finally settled on writing my own implementation of the ear-clipping algorithm to facilitate triangulation.
What We Will Accomplish
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRTXz4vpDP-KpMzkVRzKTCjzLWXhDHV7yb6VOoJBMQx1dNUF6IhqSBoK1V944GaQ460y6ZZ3clqxF37I04-m5GKGgO6Bn6iJAPd-2EUpfIp-sWyO12nCD3GA-Z_jI8qREZNkugG_dX2dY/s320/before.png) |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFbvOyqld7DgIyRxkAmNorxel32Kqk0Ol1ZpKjMN3ZELRIybXxyAyif4w1Hb-9WseykwT6EJWIDFJfKYNiPXRJt_uSzp7dRKgkE0mkPMBOju1T4IYcve87nOIVQpLfEmkq0NzTkZxCQCM/s320/after.png) |
139-vertex polygon |
Triangulated |