Computer Science 155: Graphics
Spring 1998
Homework 2

The early due date is Saturday, February 7 before midnight.
The regular due date is Sunday, February 8 before midnight.
The late due date is Monday, February 9 before midnight.

A friendly word of advice: Start this homework early! Although the algorithms are not difficult, there are several data structures to maintain and you'll need some time to design and debug your program.

Please remember to include your name, program name, and compiling instructions at the top of the file.

In this assignment you will be implementing the Sutherland-Hodgman polygon clipping algorithm and the scan-line (Active Edge Table) polygon filling algorithm. In the next assignment, you'll be integrating this into your own 2D version of OpenGL.

Your program should include the dimensions.h file which you can set to specify the dimensions of your framebuffer. Remember that the dimension values should be powers of 2. Your "main" function should take the following command-line arguments: left, right, bottom, top, x1, y1, x2, y2, ..., xn, yn, where left, right, bottom, and top are the (integer) boundaries on which to clip and (x1, y1), (x2, y2), ..., (xn, yn) are the (integer) coordinates of the n points of the polygon. (By including values left, right, bottom, and top, you will be able to clip to a viewing area that is a subset of the framebuffer.)

The first function that you will write is the Sutherland-Hodgman analytic polygon clipper. This function will take as input the values left, right, bottom, and top and a linked list of the points on the polygon. The clipper will return a linked list comprising a new polygon clipped to the four boundaries: left, right, bottom, and top. Don't write separate code for clipping to each of the four boundaries! Instead, your clipper should call another function which takes as input a polygon linked list and a clip line (and probably an orientation indicating which side of the clip line is inside the viewing area), and returns a new polygon list clipped to that line.

The next function is the active edge table polygon filling function. This function will take as input a linked list of points describing a polygon (this will be the linked list that the polygon clipper just computed) and will use the edge table and active edge tables to scanconvert the polygon into the framebuffer. (You do NOT need to implement the optimization descriped in class that encodes the inverse slope using only integers.)

Finally, the "main" function should output the rendered clipped polygon (as rgb triples scanning from the bottom row to the top row and from left to right) to standard output. (Note that if your framebuffer is large and your clip area is set to be fairly small, most of the framebuffer that you output will be black.) Use the display program to view your rendered polygon and do some testing to make sure that your clipping and filling is behaving correctly.

Leave your completed homework submission in a file called hw2.cc in your designated homework submission folder. The time stamp on that file will indicate your submission time.