public static void DrawPolygon(Polygon polygon, Color color)
 {
     GLUtil.SetColor(color);
     Gl.glBegin(Gl.GL_LINE_STRIP);
     {
         foreach (Point p in polygon)
         {
             Gl.glVertex2d(p.X, p.Y);
         }
     }
     Point point = polygon.VertexList.First();
     Gl.glVertex2d(point.X, point.Y);
     Gl.glEnd();
 }
        public static void DrawFilledPolygon(Polygon polygon, Color color)
        {
            Triangulator tr = new Triangulator(polygon.VertexList.ToArray());
            int[] indices = tr.Triangulate();

            GLUtil.SetColor(color);
            Gl.glBegin(Gl.GL_TRIANGLES);
            {
                foreach (int index in indices)
                {
                    Point p = polygon.VertexList[index];
                    Gl.glVertex2d(p.X, p.Y);
                }
            }
            Gl.glEnd();
        }
 public Polygon AddPoint(Point point)
 {
     if (_mouseNearFirstVertex)
     {
         // Special case on completing the polygon.
      //   _vertexList.Add(_vertexList.First());
         Polygon p = new Polygon(_vertexList);
         _vertexList.Clear();
         // reset the highlight
          _mouseNearFirstVertex = false;
          _highlightCircleTween = new Tween(0, 0, 0);
         return p;
     }
     else
     {
         _vertexList.Add(new PolyVertex(point, new Tween(0, 10, 0.5, Tween.BounceEaseOut)));
     }
     return null;
 }