Lab 2 - Software Rasterizer: Single Triangle

This assignment is due on Wednesday 1/17.

You must work individually.

Overview and Context

For your first assignment, you will be writing a program to render (draw) an indexed face set (a.k.a. polygonal mesh of triangles) as an image via software rasterization. We are continuing to build some basic tools for the assignment.

Goals for Today’s Lab

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

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:

For example:

Usage: .\Lab02 filename width height x0 y0 r0 g0 b0 x1 y1 r1 g1 b1 x2 y2 r2 g2 b2

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. 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 , , and between 0.0 and 1.0. For debugging this step, ignore the colors from the previous step and try drawing a red triangle.

lab2_1

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 , , and that were computed in the barycentric coordinate computation. See the example figure below for an idea of what your rasterized triangle should look like.

lab2_2

Lab Check

For lab credit you will need to demonstrate your working code on several vertex tuples specified by the instructor or the TA.