Project 1
CS351: Introduction to Computer Graphics

Email image from compiled program: Wed, Sept 29th
Final program Due 11:56pm, October 2nd

Triangle specification that produces the image to the right:

setColor3(255,0,0); /* Red */
setColor3(0,255,0); /* Green */
setColor3(0,0,255); /* Blue */

The goal in this project is to modify a triangle drawing function to linearly interpolate vertex colors across the triangle. You are given a C program which brings up an OpenGL window, but it doesn't use OpenGL to draw triangles. Instead, it copies an array of pixels into the window. We draw triangles ourselves by modifying elements of the array.

Getting started

Here is a Makefile and a set of input files that you should modify. If you want to work in C++ rather than C, change the extension of the source files from .c to .cpp, and you're ready to go. I'd suggest sticking with C for this assignment to keep things simple.
You can download all of these files individually below, or just download proj1.tar.gz

Your completed project must compile and run on one of the classroom PCs or on my mac (OS X). Be sure to give yourself enough time to get the project to compile here at school. Try compiling the code above right away to make sure you know how to do it.

To compile the program on the classroom PCs, put all these files in a directory and then type:

make BOX=dell

This runs the Makefile, a kind of script which knows how to compile and link this OpenGL program on different kinds of Unix machines. You tell it what kind of machine you're on by setting the BOX variable. It should create the executable, called canvas. To run the executable, type canvas. You should get a window with two triangles in it.

Note: Some people have trouble getting the Makefile to work because they download it to a Windows machine, and then transfer it to their Unix account. In the process, TAB characters get replaced by spaces, which unfortunately ruins the Makefile (arr!!). I suggest downloading the Makefile directly from your browser to your Unix account.

Note: You might need to do a few things differently to get the program to compile and run, depending upon what architecture of you are using.

The project

Your job is to modify the program. The triangle drawing function mimics the OpenGL syntax, with seperate calls to set a color, create a vertex, and finally draw the triangle. You should change the calling code in canvas.c so that it changes the current color before each vertex, and change the actual drawing code in lowlevel.c so that it linearly interpolates the colors along each edge, and linearly interpolates the edge colors along each row. You probably will want to change the vertex data structure so that it stores a color as part of each vertex.

I've also written a function to read triangles(begin, colors, vertices, end) from a file to make it easy for me to test your programs. You can and are encouraged to create as many input files as you like. To use the input file instead of the triangles you provide in your display loop, just run the program with an additional argument, for example:
./canvas tri1.input

You may not use the sqrt function or any other function in the math library. They all take a long time and are not realistic for rasterization code. You may not use OpenGL to draw triangles!

You'll get 90/100 for doing the interpolation in floating point, and drawing a picture with several triangles in it, with different colors. One way to get full credit is to do it with only integers and with only addition operations in the inner loop in drawRow (basically interpolate colors the same way x is interpolated in the given rasterization code). But I strongly recommend that you begin by implementing the linear interpolation using floating point, get a nice picture, and then worry about how to do it with integers after you have something to hand in.

If you're doing most of your work in Unix, this project might be a good opportunity to start using a debugger. A good user interface for debugging is ddd. It will come in very handy later. To get started, start up ddd, open the canvas program, and click on Help.

What to hand in

If we can't get our class blackboard page up, then you'll have to either email your project to or set up a web page somewhere and email the link.

We want your source code(.C, .h, .cpp), your executable, the Makefile, any input files we need to run the program. We also want an ascii (text only) file called README explaining how to compile and run the program, and how you did the color interpolation.