Lab 1 - Software Rasterizer: Bounding Box

You must work individually.

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

Overview and Context

Over the next 2 weeks, we will be writing a program to render (draw) an indexed face set (aka 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 Today's Lab

For today, we will just be playing with the provided image code to build up functionality that will be useful in your rasterizer.

Step 1

We'll be using g++ and CMake throughout this quarter. We'll also be using "out of source" builds.

If you're using the lab machines, g++ and CMake are already installed. To compile and run your code from the command line, follow these steps from the folder containing CMakeLists.txt.

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

You should see some output on the console. Look at main.cpp to see what the command line arguments mean. Once you enter the correct arguments, you should see the following output file in the build directory.

If you're using your own computer, follow the steps below to install g++ and CMake. Otherwise, you can skip to Step 2.

Linux

Use a package manager to download cmake. For example, with ubuntu,

> sudo apt-get update 
> sudo apt-get g++
> sudo apt-get install cmake

Follow the steps above to build and run the program from the command line.

OSX

You can use homebrew/macports or install these manually.

Make sure the commands g++ and cmake work from the command prompt.

If you want to use Xcode as your IDE, then do the following from the folder containing CMakeLists.txt.

> mkdir build 
> cd build
> cmake -G Xcode ..

This will generate Lab01.xcodeproj project that you can open with Xcode.

Windows

You'll need to download these manually.

Make sure the command cmake works from the command prompt. On Windows, you'll be using Visual Studio as the IDE. Run the following from the folder containing CMakeLists.txt. to generate a solution file.

> mkdir build 
> cd build
> cmake ..

By default on Windows, CMake will generate a Visual Studio solution file, Lab01.sln, which you can open by double-clicking. If you get a version mismatch, you may have to specify your visual studio version, for example:

> cmake -G "Visual Studio 14 2015" ..

Other versions of Visual Studio are listed on the CMake page (http://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).

Step 2

Starting with the provided code, make the list of command line arguments take the following options (in exactly this order)

Usage: Lab01 filename width height vax vay vbx vby vcx vcy

Thus for example – a valid program execution would look like:

./Lab01 out.png 200 200 2 2 50 60 150 170

For today 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.

Lab check

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