I have a list of several polygons.
Some are completely separated and non-intersecting with other polygons.
And some are fully intersecting and enclosed within other polygons:
I want to tesselate it to a set of triangles so I can draw them. I think that I have a code that works - I'm doing something similar to that:
tess = gluNewTess()
gluTessBeginPolygon (tess)
for polygon in polygons:
gluTessBeginContour(tess)
for point in polygon:
gluTessVertex(tess, point, point)
gluTessEndPolygon(tess)
gluDeleteTess(tess)
I'm wondering if that is the expected way to go?
The main reason I'm asking the question is that as you can see - the entire code is wrapped in a single gluTessBeginPolygon-gluTessEndPolygon. But it is actually a set of different polygons, which seems a bit odd (although it seems to work...)
This is actually the way to go (see also this example). The "polygon" defined is actually a multi-polygon here, so all that matter are the contours, which you are defining properly. OpenGL then checks internally whether some contours are self-contained or otherwise complicated and generates the proper polygon/set of polygons --- you can have a look at the code in PolygonTesselator or at this page for a walkthrough.