CMSC 435/634: Introduction to Computer Graphics

Assignment 2
Rasterizer
Due September 24, 2002

Now with color coded updates, new....old.
Last update: 09/16/02 12:18 pm

IMPORTANT UPDATE

There was a bug in my big point plot() function the version of polygons.c available before 09/13/02 05:20 pm. If you copied polygons.c before this date, please make the following change:

replace

    glVertex2f((x+cos(a))/2, (y+sin(a))/2);
with
    glVertex2f(x + cos(a)/2, y + sin(a)/2);

The assignment

You are going to implement a version of the GL_POLYGON OpenGL drawing function. I have provided a sample program that reads polygons from an input file and draws them using the real GL_POLYGON. You should write replacement functions for glBegin, glVertex2f, and glEnd. For the extra credit/634 portion described below, you will also need to write a replacement for glColor3f. You may call these functions myBegin or something similar. Your version should plot big points with the plot() function provided and outline the triangle with lines (which you can draw using the built-in GL_LINE)

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. A sample input file can be found in ~olano/public/435/assn2/paint.pgon. This file should be piped into the example program:

polygons < paint.pgon

634 students / 435 extra credit

For extra credit (required for 634), implement a per-vertex color feature. Polygons will be optionally specified with an additional color at each vertex instead of one for the entire polygon. You should linearly interpolate between these colors across the pixels of the polygon. If a polygon is given with both a polygon color and color per-vertex, use the vertex colors. For example:

# triangle with red, green, and blue vertices
3	
1	1		1.0 0.0 0.0
1	5		0.0 1.0 0.0
5	1		0.0 0.0 1.0

A sample input file can be found in ~olano/public/435/assn1/paint.xc.pgon. The maximum points available for this feature is 10.

Clarifications

Your output for a single polygon might look something like this:

What to turn in

Turn in this assignment electronically as 'cs435 Proj2' (even if you are in 634) using the submit mechanism:
    submit cs435 Proj2 [files...]
If submitting after the due date, submit as Proj2late. In either case, you should submit your Makefile, source code, and an image generated with paint.pgon (and, if applicable also paint.xc.pgon). The sample program will save an image if you hit the 's' key, but it always uses the same name so you will have to rename this file to save more than one image.

Your comments should include information about which computer platform (HW and OS) you developed your program on. Your program will be graded on the gl systems, so if you develop someplace else, allow time to port to back to the gl machines. As always, additional comments may help your grade in cases where your program does not operate entirely correctly (since they can give me insight into what you were trying to do). In any case, your programs are expected to be robust and easy to understand.

References

For anyone looking for more information on OpenGL, the irix machines include all of the OpenGL man pages (you don't have to be sitting at one, you can just 'ssh irix.gl.umbc.edu'). Just try 'man glVertex2f', etc. to find out more about any function used in the assignment that sparks your curiosity. Also, the OpenGL 1.1 Programmers Guide (the "OpenGL red book") is available online. This a good introduction to writing OpenGL programs.

Working at home

Once again, if possible, I urge you to use the university computers for your work. I test things out on the gl systems and may or may not be able to help you if things don't work right for you at home. If you do work at home, your final submitted version must be able to run on the gl machines and must be electronically submitted there.

If you absolutely must work at home, you will need:

All of these libraries are cross-platform and run on both unix and windows. However, if there are no pre-built binaries for your platform, you may end up having to build them from the source downloads. Which brings me back to: if you don't have to work at home, don't.