Due: See Schedule for Due date
(100 points)
Overview
For this program you will build a 2D polygon fill routine. Polygons with more than three vertices will be treated as triangle fans, as per OpenGL's POLYGON mode. To do this, you will implement the edge table technique and fill the polygon using the OpenGL POINT primitive. You may not use any other primitive; if your code contains glBegin(X) where X is not GL_POINTS, it will not be accepted.
This program will be extended and used as part of the remaining programs, so you should design it well.
You will read polygon descriptions in from a file in the format given below. You should design a Polygon class to store the polygons into, and then keep track of all of the polygons in your scene. Once all of the polygons have been read in, you will then draw the filled polygons. A good data structure design will assist you greatly in this assignment.
The given input file anticipates a 700 by 700 window. You will likely want to make your own inputs and be able to resize your window.
Requirements
See also the hints for project 1, which are a collection of best practices which should meet the requirements for this project.
To pass off this program, you will need to write your own code which
- Can read the file format noted below.
- Uses OpenGL POINT primatives to do all of its drawing (no TRIANGLEs, QUADs, etc).
- Draws polygons with any number of points (3 or more) as a triangle fan.
- Linearly interpolates color between the vertices.
- Does not leave gaps between neighboring triangles.
- Draws each pixel within a triangle (possibly excepting the edges) only once.
- Can produce from the example input file something that looks like the example output. This should follow automatically from the other requirements.
You should pass off with the TA in person. If you want the TA to use the timestamp of your files rather than the time you show up to pass off, you are responsible to bring that up and show the timestamp to the TA.
File Format
The file format that you will read from for this program is defined as follows:
- Each polygon will be represented by two lines in a file.
- The first line will contain an integer that will specify the number of vertices of the polygon.
- The second line contains a multiple of 5 integer values: the (x, y) coordinates of a vertex followed by the color (r, g, b) of that vertex. Colors are between 0 and 255, the range anticipated by a glColor3ub(r, g, b) call.
For example, a sample file might look like:
4
50 50 0 255 0 100 200 0 255 0 400 100 0 255 0 10 350 0 255 0
3
500 10 0 0 255 20 400 0 255 0 350 350 255 0 0
Which, when read line by line, means "The first polygon has four vertices. These 4 vertices are located at 50,50; 100,200; 400,100 and 10,350; all are green." Then, "The second polygon has 3 vertices. These vertices are located at 500,10 (blue); 20,400 (green); and 350,350 (red)".
Extensibility Considerations
Future projects will build on this project. It's not a bad idea to preview future projects so that you'll have some idea of what you need to add later. The extensions you will need to make for future programs (just so that you can plan ahead) include:
1. Extending your system to deal with 3D polygons.
2. Comparing the Z value of each point in the polygon against another Z value.
3. Specifying just one color for an entire polygon
4. Computing a lit color for each point in the polygon. (Store a single base color for the polygon that will be altered to allow for lighting and shading.)
5. Adding other polygon material properties that we will discuss in class.
Related Files
- Example input file (txt)
- Output from example input file (png)
- Hints for project 1
- see also OpenGL notes.





