Write a program that reads polygon descriptions from a file, and displays them using the GLUT library. Don't clear the image after each polygon, draw later polygons on top of earlier ones. The last polygon listed in the file will lie on top of all of the others. This is called the Painter's Visibility Algorithm, since it simulates the process a painter would follow to paint a picture.
The input file describes a sequence of polygons. Each polygon description begins with a header line containing the number of vertices of the polygon and the fill color (given as red, green, and blue values). Following the header line are lines giving the coordinates of the vertices, one line for each vertex. Lines which begin with a '#' character are comments and can simply be ignored. A simple polygon description might look like this:
# red triangle
3 1.0 0.0 0.0
1 1
1 5
5 1
This describes a red triangle.
Here’s a sample input file. Here’s a sample code segment to draw lines without using glVertex functions.