Drawing a mesh or polygon from a set of vertices

Hello everyone!

I’m attempting to draw either a mesh or a 2D polygon from a set of Vector2 vertices (my game is 2D). The purpose of this is to create a “shadowed” area where the player can’t see. I have all my vertices but it appears I now need a set of “triangle indexes” to feed into my mesh.

So, how does one create such an array? What are those indexes?

I tried using pre-made algorithms such as the triangulator seen here but it doesn’t cover all cases and often my mesh appears clipped or the triangulation is wrong, “skipping” a few vertices. I would like to create my own algorithm for this if needed but I have no idea what the triangle indexes are supposed to be in the first place.

Also, is there another way to achieve the same effect without programatically drawing a mesh?

indexes is a array of int. values of this array is indexes of triangle vertexes. for example if you have 4 vertices = [vertex0,vertex1,vertex2,vertex3] and 2 triangles indexes array will be

[0,1,2,2,3,0] its mean that its contains 2 triangles = with vertexes [vertex0,vertex1,vertex2] and [vertex2,vertex3,vertex0]

Got it! Thanks Prefab!

Still open to other drawing techniques from a collection of points, if anyone has any.