# Assignment 3: Rasterization Solution

\$30.00

Category:

## Description

In this assignment we will explore basic image rasterization algorithms. This is an individual assignment, i.e., you have to work independently. All information needed to complete this homework is covered in the lectures and discussed at our Canvas Discussion Boards. You shouldn’t have to use any textbooks or online resources, but if you choose to do so, you must reference these resources in in your final submission. It is strictly prohibited to reuse code or fragments of code from textbooks, online resources or other students — in this course this is considered as academic misconduct ( ​https://www.cs.utah.edu/academic-misconduct/ ). Do not share your homework solution with anyone — this is also treated as academic misconduct in this course,​​even​​if​​nobody​​ends​​up​​copying​​your​​code.

The​​framework​​code​​is​​written​​in​​C++​​with​​the​​following​​dependencies:

• OpenGL​​0
• GL​​Utilities​​(GLU)

• C++​​STL

• OpenGL​​Extension​​Wrangler​​Library​​(​GLEW​)

The recommended IDE is Visual Studio 2017 Community Edition, which is available free of charge for educational purposes. The framework code provides precompiled dependencies for Visual Studio 2017. If you choose to use a different platform or IDE version it is your responsibility​​to​​build​​the​​dependencies​​and​​get​​the​​project​​to​​work.

The assignment should be implemented inside the provided ​main.cpp file using the specified subroutines. No other source code / dependencies / libraries are needed or allowed for this assignment. The provided source code, after being successfully compiled, linked, and executed, should​​display​​a​​black​​image.​​Your​​task​​will​​be​​to​​draw​​something​​into​​this​​image!

1​​​Line​​rasterization​​(50​​points)

Your first task is to complete the function ​drawLine(int x1, int y1, int x2, int y2). Using the Bresenham algorithm for line rasterization, this function should draw a line from pixel (x1, y1) to pixel (x2, y2). Warning: some formulations of the Bresenham algorithm support only certain combinations of points (x1, y1) and (x2, y2). Your function is supposed to be general and support all possible inputs (x1, y1) and (x2, y2). The individual pixels of the line should be written into the buffer ​g_image. You may use the provided function ​putPixel(int x, int y) which writes a white pixel into ​g_image at point (x, y). Your line drawing algorithm needs to be able to handle lines of all directions, but you can assume the points (x1, y1) and (x2, y2) are inside the dimensions of ​g_image (600 x 600). After you’ve completed the function ​drawLine, the provided function ​drawImage should draw a simple image on the screen. The same image will be also saved​​into​​file​​“data/out.ppm”.

2​​​Circle​​rasterization​​(50​​points)

The next task is to implement Bresenham’s algorithm for circle rasterization inside function d​rawCircle(int x0, int y0, int R), where (x0, y0) is the center of the circle and R is the radius. Just like in Task 1, you can assume that none of the pixels of the circle will lie outside of the g_image window.

3​​​Extra​​Credit​​(up​​to​​20​​bonus​​points​​at​​instructor’s​​discretion)

If you are looking for additional challenges, implement Bresenham’s algorithm for drawing an ellipse and use it to rasterize a new image which will use all of the three primitives (lines, circles, and ellipses) in a creative way. You can also extend the code to support different colors to create​​more​​interesting​​ i  mages!

4​​​Submission

• Your​​resulting​​image​​“out.ppm”​​showcasing​​your​​line​​and​​circle​​rasterization​​