Docsity

2 Practice Problems on Computer Graphics - Assignment 2 | 22C 151, Assignments of Computer Graphics

Toggle sidebar
bg1
Fall 2004
22C:151 Introduction to Computer Graphics
Assignment 2
Due: Thursday September 9th at 12:01am (Wednesday at midnight)
Goal: Write a program that rasterizes lines (using the Bresenham/midpoint algorithm) and outputs them to PPM files.
Write a second program that draws the same lines using OpenGL and GLUT.
Problem 1 (10 points): (8 points) Write a program that rasterizes the following lines into a 512 ×512 buffer (in
memory), and output the result to a PPM file. The background should be black (i.e., RGB = [0,0,0]). Use a utility
program to convert the PPM file to GIF, PNG or BMP to display on your web page (use ppmtogif,ppmtobmp, or xv
on Linux systems or GIMP on Windows systems).
•Ared line from (0,0) to (511, 511)
•Agreen line from (32, 490) to (351, 63)
•Ablue line from (0,511) to (32, 10)
•Awhite line from (0,511) to (502, 480)
•Apurple (red + blue) line from (140, 0) to (180, 250)
•Ayellow (red + green) line from (400, 420) to (400, 50)
•Acyan (green + blue) line from (420, 400) to (50, 400)
(2 points) In a second 512 ×512 image, draw the same five lines, but change colors gradually from one end to
the other. For example, draw the line from (0,0) to (511, 511) starting at red and gradually blending to green at (511,
511). I want you to think about and come up with a blending method on your own. There is no right or wrong way
to blend here, as long as the color varies gradually over the line. Make sure to use contrasting colors at the endpoints
(white & black, red & green, yellow & blue, etc.)
Problem 2 (10 points): (5 points) Write an OpenGL/GLUT program that draws the same lines as in Problem 1
(using the same colors). Using a keyboard callback, allow the user to switch back and forth between the solid lines
(glShadeModel(GL FLAT);) and those with gradually varying colors (glShadeModel(GL SMOOTH);) by
hitting the key ’c’. Capture the result in an image and post on your web page. Make sure to label your images, so I
know which is from Problem 1 and which is from Problem 2.
(5 points) Allow the user to draw an additional line by clicking the right mouse button at the two endpoints.
Extra Credit (5 points): Combine both problems into a single OpenGL program. Using a keyboard call-
back, allow the user to switch from OpenGL rendering to your own rasterization technique. Make sure to la-
bel your window (perhaps using glutSetWindowTitle(char *title);), so the user knows which mode is active. Use
glBegin(GL POINTS); to draw each pixel.

Partial preview of the text

Download 2 Practice Problems on Computer Graphics - Assignment 2 | 22C 151 and more Assignments Computer Graphics in PDF only on Docsity!

Fall 2004

22C:151 Introduction to Computer Graphics

Assignment 2

Due: Thursday September 9th at 12:01am (Wednesday at midnight)

Goal: Write a program that rasterizes lines (using the Bresenham/midpoint algorithm) and outputs them to PPM files. Write a second program that draws the same lines using OpenGL and GLUT.

Problem 1 (10 points): (8 points) Write a program that rasterizes the following lines into a 512 × 512 buffer (in memory), and output the result to a PPM file. The background should be black (i.e., RGB = [0,0,0]). Use a utility program to convert the PPM file to GIF, PNG or BMP to display on your web page (use ppmtogif , ppmtobmp , or xv on Linux systems or GIMP on Windows systems).

  • A red line from (0,0) to (511, 511)
  • A green line from (32, 490) to (351, 63)
  • A blue line from (0,511) to (32, 10)
  • A white line from (0,511) to (502, 480)
  • A purple (red + blue) line from (140, 0) to (180, 250)
  • A yellow (red + green) line from (400, 420) to (400, 50)
  • A cyan (green + blue) line from (420, 400) to (50, 400)

(2 points) In a second 512 × 512 image, draw the same five lines, but change colors gradually from one end to the other. For example, draw the line from (0,0) to (511, 511) starting at red and gradually blending to green at (511, 511). I want you to think about and come up with a blending method on your own. There is no right or wrong way to blend here, as long as the color varies gradually over the line. Make sure to use contrasting colors at the endpoints (white & black, red & green, yellow & blue, etc.)

Problem 2 (10 points): (5 points) Write an OpenGL/GLUT program that draws the same lines as in Problem 1 (using the same colors). Using a keyboard callback , allow the user to switch back and forth between the solid lines (glShadeModel(GL FLAT);) and those with gradually varying colors (glShadeModel(GL SMOOTH);) by hitting the key ’ c ’. Capture the result in an image and post on your web page. Make sure to label your images, so I know which is from Problem 1 and which is from Problem 2.

(5 points) Allow the user to draw an additional line by clicking the right mouse button at the two endpoints.

Extra Credit (5 points): Combine both problems into a single OpenGL program. Using a keyboard call- back, allow the user to switch from OpenGL rendering to your own rasterization technique. Make sure to la- bel your window (perhaps using glutSetWindowTitle(char *title); ), so the user knows which mode is active. Use glBegin(GL POINTS); to draw each pixel.