Assignment 1 Sample Program


The sample program given out will get you started on building your impressionist paint program.  It loads images from disk, saves images back to disk, and provides the basic UI framework you need to complete the assignment.

NOTE: Deviating from the UI provided may break the automated testing mechanisms.  Please don't change things like GLUT menu ID's or callback names.
 

We encourage you to read the code provided.  It is well commented, and should be mostly self-explanitory.  This document will describe things that might not be obvious.

Images and Colors

A color is represented by a Color structure.  This structure contains three fields: R, G, and B.  These are each unsigned characters, and each range from 0 (black) to 255 (full intensity).

To get the color at a particular pixel, use the GetPixel() method of the Image class.  This method takes the (x,y) coordinates of the pixel to retrieve.

NOTE: The (0,0) coordinate for images is the upper-left corner.

Grabbing the pixels off the screen

Take a look at how the framework implements the "Save Image To Disk" menu item to see how to read the pixels off the screen into an image. Note that if the window is partially obscured when you try to read the image off the screen, the contents of the image in the obscured portion are undefined, but will most certainly not be what you want. You are not required to solve this problem for this assignment.

Extending the framework

The first thing to do is make your program not display the read-in image, but rather present the user with a blank canvas.  You can make the default background color of this canvas whatever you like (I prefer black).  There are two global Image variables: origImg and workImgorigImg is the original image as read from disk.  You can use it for queries like "what's the color at this (x,y) location?".  workImg is the "working", or "scratch" image.  It should hold the contents of the painting.  Notice that in the framework, workImg is constructed as a copy of origImg.  You can change this to a blank image by using the Image constructor that takes two dimensions x and y.  This constructor will create an empty (black) image of the specified size.

Note that once you have done this, you can still view the image by selecting the "Copy Orig to Work" menu item.  See the framework code to see how this is implemented.

Now you're ready to do the assignment.  You have six menu items to fill in, which set the brush shape and style.  You have controls to set to change the size of the brush. Finally, you have callbacks to fill in to handle mouse clicks and drags.  These callbacks and menu items are already in the framework; they just do nothing.  Search for the string TODO in the code, and you will see where your code should go.

NOTE:  You should use the keys 1-5 to set the brush size.  1 is the smallest, and 5 is the largest.  Deviating from this will make testing your program harder and the TAs angry.

NOTE:  You should use the key 'a' to set the alpha.  Deviating from this will make testing your program harder and the TAs angry.


CS248: Introduction to Computer Graphics, Pat Hanrahan, Fall 98