Computer Graphics I

4003-570-02 / 4005-761-02

Assignment #2: 2D Drawing Algorithms


Date posted: September 24, 2008
Date due: October 8, 2008 at 11:59 p.m.
Submit to the dropbox on the myCourses website


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. 

Task

You are to implement the following routines:

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.

Implement these using the midpoint line, scan-line conversion, and Sutherland-Hodgman Clipping algorithms discussed in class and in the textbook.   Your implementation cannot make use of any OpenGL routines with one exception - you should make use of a method setPixel(x, y) which is defined as follows:

void setPixel (int x, int y)
{
  glRecti( x, y, x+1, y+1 );
}

Auxiliary Code:

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

File Description
lineTest.c Test program for line drawing.
fillTest.c Test program for polygon fill.
clipTest.c Test program for clipping algorithm.
setPixel.c Implementation of setPixel().  You must use this function in your implementation.  No other OpenGL calls allowed!
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.
paint.c Source for paint program that will make calls to the functions that you will be implementing.  This can be used as a test program (optional).  Please see the comments at the top of the file for info on how the program operates.
header.mak If you plan on using makemake or gmakemake on the Suns.

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

READ THIS SECTION CAREFULLY

Please submit ALL files necessary to build and run the LineTest, fillTest, and clipTest programs. If you are using C, you must also include the auxiliary files provided above. If you are using another language, you must provide the rewritten versions of these files.

When using IDEs like Visual Studio or XCode, please zip and submit the entire project folder (including the executable). This greatly simplifies the grading process.

Your submission should include a file called drawStuff that contains your implementations of the routines that need to be written.

Finally, your submission must include a README that indicates the platform on which you tested your implementation and provides detailed instructions for building and running your submission.

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

Assessment

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