Polygon Coordinate Order

I’m trying to render a polygon defined by five points that change depending on the user’s view of the scene.

Unfortunately these points sometimes get out of order and the polygon clips itself.

Instead of going from points 1>2>3>4>5 it will do something like 2>1>3>4>5.

Does OpenGL have a function that will order these points in the correct way to make a solid polygon?

(If so, does it also apply to texture coordinates?)

One solution if your polygon is always convex is to compute the convex hull of your points with the following algorithm to find the order of vertex on the contour.

Anyway, if your polygon is not always convex, there will be more than one solution to build a concave polygon if you don’t know the neighbors vertex on the contour of a particular vertex.Also OpenGL is not able to draw concave polygon right away. You need to use GLU in this case or an algorithm which use the stencil buffer.