It is indeed a complicated task. However by using the Triangulator provided by the Spine Runtimes I managed to do it, worked for both concave and convex clipping polygon.
Here is my working code:
if (attachment->type == ...) {...} //Other types
else if (attachment->type == SP_ATTACHMENT_CLIPPING) {
spClippingAttachment *mesh = (spClippingAttachment *) attachment;
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength,
worldVerticesPositions, 0, 2);
spTriangulator* triangulator = spTriangulator_create();
spFloatArray* verticesArray = spFloatArray_create(mesh->super.worldVerticesLength);
spFloatArray_addAllValues(verticesArray, worldVerticesPositions, 0, mesh->super.worldVerticesLength);
spShortArray* triangles = spTriangulator_triangulate(triangulator, verticesArray);
glBegin(GL_TRIANGLES); //Draw Triangles
glColor4ub(255, 255, 255, 255); //White
for (int i = 0; i < triangles->size; i++)
{
int index = triangles->items[i] << 1;
glVertex2f(position.x + worldVerticesPositions[index], position.y + worldVerticesPositions[index + 1]);
}
glEnd();
//Free arrays...
}
The Triangulator is amazing btw, could it be a separate library?