Computer Graphics I

4003-570-02 / 4005-761-02 (Fall 2009)

Assignment #2: 2D Drawing Algorithms



Date posted: September 30, 2009
Date due: October 14, 2009


Purpose

In this project, you will implement some of the 2D drawing routines we have been discussing in class. This will help improve your understanding of these algorithms. The assignment is written for implementation in  C or in C++, though you do have the option to implement it whatever langauge you feel most comfortable with (as long as it supports OpenGL, or minimally  the drawing of a pixel on a 2D image.).

Also note that you will not be implementing a main program; instead, your reimplementations of the routines described below will be tested with a set of driver programs I will provide.

Task

You are to implement the following routines. Implement these using the midpoint line, scan-line conversion, and Sutherland-Hodgman Clipping algorithms discussed in class and in the textbook.   You implementation cannot make use of any OpenGL routines.  Instead, you should make use of the method setPixel (x, y) which will be provided for you.  (See auxiliary code section below)

Function Description
void drawLine(int x0, int y0, int x1, int y1) Draw a line from vertex (x0,y0) to vertex (x1,y1).
void drawPolygon(int n, int x[], int y[])
Draw a filled polygon. The polygon has n distinct vertices. The coordinates of the vertices making up the polygon are stored in the x and y arrays.  The ith vertex will have coordinate  (x[i], y[i])
void clipPolygon(int in, int inx[], int iny[], int *out, int outx[], int outy[], int x0, int y0, int x1, int y1)
Clip the polygon with vertex count in and vertices inx/iny against the rectangular clipping region specified by lower-left corner (x0,y0) and upper-right corner (x1,y1). The resulting vertices are placed in outx/outy, with the vertex count placed in out.

If implementing in a language other than C or C++, your parameter list may vary based on the specifics of your chosen lanaguage.

Auxiliary Code:

Below is a list of links to code that will help you in completing this assignment:

File Description
drawStuff.c Default implementations of the functions that you need to implement.  These default implementations make use of OpenGL calls.  They are supplied so that you might compile the test programs and see how they should work.   Note that the implementation provided for clipPolygon is especially dumb and will not clip correctly.  You can use this file as a template, and replace function code with your implementation.
setPixel.c Implementation of setPixel().  Recall that you must use this function in your implementation.  No OpenGL calls allowed!
header.mak If you plan on using makemake or gmakemake on the Suns.
lineTest.c Test program for line drawing.
fillTest.c Test program for polygon fill.
clipTest.c Test program for clipping algorithm.

If you want all of the above files in a single download, here they are in zip and tar format.

For your comparison, the correct output for each of the test programs are provided below:

NOTES:

What to submit

You will be submitting the following files:

Filename Description
drawStuff.c Contains implementations of the routines that need to be written.  Feel free to use the supplied drawStuff.c as a template, replacing the original code with your implementation
aux files Any additional files that  might be needed for your implementation (optional)
README Indicate on what platform you tested your implementation and provide additional info I may need to know (e.g. auxillary libraries used) in order to build and run your assignment.

All submission should be made using mycourses.   Look for the folder named "Assignment 2 " in the dropbox area.

Note: If you are not using C or C++, you must reimplement the test programs in the language that you are using.  Please include the reimplemented test programs with your submission.  In short, I should be given enough code and info to rebuild and run your assignment on the machines in my office.

Assessment

Your grade will be based on your reimplementation of the required routines and their usability with the supplied test programs. 

last updated 09/30/09