CS 551/645: Introduction to Computer Graphics

Assignment #3

Goal: Learn about and implement efficient scan conversion of triangles, with Gouraud shading.

Assigned: Wednesday, September 22, 1999

Due: Wednesday, September 29, 1999

Relevant reading/files/software:

Synopsis: You will design and implement a 2-D scan conversion algorithm for triangles that uses the general approach of edge walking, as opposed to edge equations. Your algorithm will take three R,G,B color tuples as well as three pairs of X,Y coordinates for the triangle corners, linearly interpolating colors down the edges and across the spans to fill in interior pixels. The algorithm will be graded, first, on correctness, and second, on speed. As with assignment 2, your algorithm will be packaged as a library that we will link our testing programs with; we will provide the interface for the library functions you write. We will also provide an extended framebuffer class with support for writing the framebuffer to an image file, and a function that takes an image file and highlights the differences between the framebuffer and the image in the file. Finally, we will supply some simple test programs that use the library, as well as images of what the programs should produce.

Specifics: We are providing a header file tri.h defining function prototypes for the library; you will have to fill in the source code (tri.c) for those functions. We provide the header file and source code for the framebuffer library (frame.c, frame.h); we are also providing a Makefile that includes rules for making the framebuffer library (libframe.a) and the triangle library (libtri.a) that you will be creating. Finally, we will supply a file gfx.c with functions to draw the framebuffer into an XForms glCanvas, to write the framebuffer to a .ppm file (viewable on UNIX systems with the xv command), and to diff the framebuffer with an image from a ppm file. This last function should prove useful for debugging, but you are responsible for figuring out how it works and building a tool to use it. A few things to note:

Test Files: To aid you in testing your code, we are providing test files (some stolen from Professor McMillan, again) in the following format:

x1 y1 color1 x2 y2 color2 x3 y3 color3

x1 y1 color1 x2 y2 color2 x3 y3 color3

x1 y1 color1 x2 y2 color2 x3 y3 color3

etc…

Here x and y are floating point values (in human-readable string form) and color is a hexadecimal integer of the form 0xRRGGBBAA (R=red, G=green, B=blue, A=alpha). We are also providing .ppm files of what the resulting images should look like.

Files: hexcone.tri, teapot.tri, cow.tri, and if you set FB_WIDTH and FB_HEIGHT to 25: smalltests.tri

Images: hexcone.ppm, teapot.ppm, cow.ppm, and if you set FB_WIDTH and FB_HEIGHT to 25: smalltests.ppm

Some people seem to be having difficulty reading in and drawing the .tri files, so I'm making code available that does so.

Grading: The usual 10-point scale. An assignment that does everything correctly will receive 8 points. Fast algorithms (that still produce correct output!) can earn up to 9 points. Points will be deducted for assignments that don't compile "out of the box", or that somehow produce incorrect output (e.g., gaps between triangles, incorrect color values). The single fastest (and entirely correct) assignment gets a 10.

Turning in the assignment: Before class starts on Wednesday, September 29, you should:

Advice: This one will probably be tougher than the first two. It's not hard to write a bad triangle rasterizer, but getting all the special cases right and dealing properly with the color interpolation can be a job. Start early!