CS 351: Assignment #4

Title image Spring 2017

Polygons

Due 2 March 2017

In this assignment you'll implement both a polygonAPI and the scanline fill algorithm for polygons. The algorithm is probably going to become the most used piece of code you'll write this semester and will be central to your rendering system. As such, take care to comment the code and understand what is going on.


Tasks

  1. Implement a subset of the polygon API functions in the C Graphics System Specification.
    • polygon_create
    • polygon_createp
    • polygon_free
    • polygon_init
    • polygon_set
    • polygon_clear
    • polygon_setSided
    • polygon_copy
    • polygon_print
    • polygon_normalize
    • polygon_draw
    • polygon_drawFill
    For this project, your Polygon structure does not need the color, normal, or zBuffer fields.
  2. Implement the scanline fill algorithm for polygons. You can write it from scratch, use the version in one of the textbooks, or use this scanfill skeleton code as the basis for your function. Make sure that your algorithm uses the correct placement of the coordinate grid (lower left corner of the pixel). The name for this routine should be polygon_drawFill(). Your algorithm should not create a border that is a different color than the fill color. Just draw the filled in polygon as a single color (for now).

    If you want to do a gradient fill, texture fill, or pattern fill, create separate functions for them.

  3. Implement a second polygon fill algorithm, polygon_drawFillB() that uses barycentric coordinates to determine which pixels to fill given a polygon with only 3 points. Scan over the bounding box of the triangle, filling any pixel whose barycentric coordinates are all in the range [0, 1]. The lecture notes give the equations.

    When calculating which pixels to fill, use the center of each pixel to make the determination. That means you need to add 0.5 to the x and y value of the pixel coordinates when calculating the barycentric coordinates.

    Don't worry about handling special cases (boundary going through the pixel center) for now. Note that test file B shows that drawing the polygons this way is order dependent.

  4. One required image is the same as the previous assignment, a picture of a car, train, plane, or spaceship, except that a majority of the surfaces should be colored/filled in.
  5. Use test file A to create the second required image.

    result for test file A

  6. Use test file B to create the third required image.

    result for test file B

  7. Create two images for your portfolio using the techniques you have developed so far and any extensions you decided to pursue.
  8. If you wish, try running the testbench program for your fillscan and barycentric polygon functions. Note that the program makes use of a Color_set function, so you'll need to add that to your library.
  9. You can also try out the Polygon stress test file to see how your various polygon memory management functions are doing. Here is the expected result. If you really want to test for memory leaks, try out test4c-loop.c and then use the command line tool top to watch your memory usage. You'll have to use cntl-c to stop the top program.

Extensions


Writeup

Make a wiki page and give it the label cs351s17project4. Put up your required and portfolio images along with brief descriptions and relevant information.


Handin

Put your code on the handin server in a project 4 directory in your Private folder.