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/AVvXsEjSYI88UkCVdkYcltfGjRnAng0ewYzKYGA50TekVK20UOniYoNlVjQc7JNKp08mR-NJk74UNb6CIlLC1mwL79C1DEB3o8DHRx723K_mjzSHaScABpQFUa0xK0VE8-LD7VF56sfhz7HLXqE/s320/before.png) |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgET53aWW0J9kvLshc3Y5dvz29-mQJA5UjnZ4X1WWerTeXJWA24lgZBAmwuwCQxkQqVe_VdRsIkgf02QKed02UwFZdS-PbKpUxstFu2tw3iGbcsMqJUX5KUujCh96DkWvgBafm2v0XDOCY/s320/after.png) |
139-vertex polygon |
Triangulated |