Home

Lab 2 - Rasterizer: Single Triangle

Overview and Context

We are continuing to build some basic tools for Assignment 1.

Goals for This Lab

For this lab, you will add onto your first lab and only rasterize a single triangle. Your program must:

Step 0

Copy over CMakeLists.txt and the src folder from the previous lab. Change the name of the project in the CMake file. Build and run the executable as before. E.g., with command line,

> mkdir build
> cd build
> cmake ..
> make -j4
> ./Lab02

With Xcode:

> mkdir build
> cd build
> cmake -G Xcode ..
> # Open Lab02.xcodeproj with Xcode 

With Visual Studio:

> mkdir build
> cd build
> cmake ..
> # Open Lab02.sln with Visual Studio

Step 1

Starting from your Lab01 code, add command line arguments to read-in three different red, green, blue values to the three different vertices. (Consider differing colors that make a blended color you can reason about such as red and blue or yellow and blue – look up any RGB color chart to pick good colors.) The command line arguments should be:

./L02 foo.png 512 512 100 100 255 0 0 400 100 0 255 0 200 300 0 0 255

You can also hard code these values in your code.

Step 2

Using your prior code, compute the bounding box of the triangle. Now for every pixel in the bounding box, compute the barycentric coordinates for each pixel. You may “borrow” some code for this from the web, but if you do, make sure to cite the source in your code (and README for assignment).

Draw the triangle, rather than just the bounding box, by using the fact that any pixel that falls within the triangle will have \(\alpha\), \(\beta\), and \(\gamma\) between 0.0 and 1.0. For debugging this step, ignore the colors from the previous step and try drawing a red triangle.

Step 3

For any pixel that will be drawn, its color should be a blend of the colors specified at the triangle vertices. Blend the colors using \(\alpha\), \(\beta\), and \(\gamma\) that were computed in the barycentric coordinate computation. See the example figure below for an idea of what your rasterized triangle should look like.


Generated on Thu Jan 20 12:08:13 CST 2022