Home

Lab 1 - Rasterizer: Bounding Box

Please download the code for the lab and go over the code.

Overview and Context

For Assignment 1, we will be writing a program to render (draw) a polygonal mesh of triangles as an image via software rasterization (i.e. the code will be entirely written in C/C++ with no graphic libraries. The software will render a static scene). In general the required steps for the program will be:

We will discuss the window coordinate transform, barycentric coordinates and z-buffers in the next few lectures.

Goals for This Lab

For this lab, we will just be playing with the provided code (main.cpp) to build up functionality that will be useful in your rasterizer.

Starting with the provided code, make the list of command line arguments take the following options:

./L01 foo.png 512 512 100 100 400 100 200 300

You can also hard code these values in your code.

For this lab only, we will assume the triangle’s vertices are in “window coordinates.” In other words, the data values are integer values that range from 0 to the value of width-1 of the window/image (or 0 to the height-1 value of the window/image). You may choose to have the vertices be 2D (although for the Assignment 1, they will need to be 3D). You will need to design a data structure to represent the triangle and its vertices. Draw the three vertices into the image, using three calls to image->setPixel().

The bounding box of the triangle is the box with the extents that will exactly bound that triangle. You will need to design a data structure to represent the bounding box. At minimum such a structure needs xmin, xmax, ymin, ymax. Using the provided image code, modify the color of all the pixels in the bounding box to be a color of your choice (which is different then the background).

You can also try a pattern based on the row and/or column. The three vertices and the bounding box should look something like this:

Write out the modified image and confirm your code is working as expected. Be sure to try various test cases with vertex positions in various orders. Make sure the bounding box completely covers the three vertices.


Generated on Thu Jan 12 09:40:19 CST 2023