I am creating a 2D Openstreetmap rendering application for Android using OpenGL ES.
Unfortunately I am struggling with drawing concave polygons consisting of approximately 50 or more points. In order to accomplish that my polygons are filled, I am using GL10.GL_TRIANGLE_FAN:
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertBuff); // size = 2 because 2D
gl.glDrawElements(GL10.GL_TRIANGLE_FAN, pointCount, GL10.GL_UNSIGNED_SHORT, indexBuff);
This approach works fine as long as my polygons are not too complex, for example drawing a polygon like this is no problem at all:
My problem is, that GL_TRIANGLE_FAN always starts at the first point (a in this case) and then uses 2 other points to draw a triangle, until the whole shape is complete.
If a more complex polygon has to be drawn, this can lead to issues as you can see here:
(in this example, the river that flows through the city is a complex polygon)
My question now is how to avoid this problem so that even complex polygons are drawn correctly and filled?
The problem lies in drawing concave polygons.
When using GL_TRIANGLE_STRIP instead of GL_TRIANGLE_FAN, the polygons are drawn, correctly, but only their points are connected together by triangles, the polygon itself is not filled.