Triangle specification that produces the image to the right:
beginTriangle(); |
![]() |
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.
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.
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.
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.