You must work individually.
For your first assignment, you will be writing a program to render (draw) an indexed face set (aka polygonal mesh of triangles) as an image via software rasterization. We are continuing to build some basic tools for the assignment.
For today, you will add onto your first lab and only rasterize a single triangle. Your program must:
Copy over CMakeLists.txt
and the src
folder from Lab01. 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
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:
Usage: L02 filename width height x0 y0 r0 g0 b0 x1 y1 r1 g1 b1 x2 y2 r2 g2 b2
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. Please write your own code, refer to the reference provided on the webpage.
Draw the triangle, rather than 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.
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.
For lab credit you will need to demonstrate your working code on several vertex tuples specified by the instructor or the TA.