Assignment 1 - Sketchpad
CS4961 - Computer Graphics
Due January 24, 2001, 10:45 AM
Overview
This assignment serves as a quick introduction to building projects using GL, GLUT, and GLUI. You have been provided with all the code needed to create a simple sketchpad application similar to Microsoft Paint. Your job is to build a user interface for it. The interface may be built using GLUT and GLUI as necessary. I would recommend that you spend time gaining familiarity with these libraries as they provide a relatively simple way to create responsive user interfaces. Subsequent projects in this class will require some sort of user interface to be developed.
Project Requirements
The following are requirements for the project. Your grade will be based on whether you completed all of them.
Your program must:
- Draw points on the screen. Clicking a mouse button within the drawing window should immediately draw a point. Likewise, holding the mouse button down while dragging the mouse across the window should produce a series of points following the path of the mouse. [NOTE: because of the rate at which GLUT checks motion events, points due to a drag event may end up separated from each other by some distance if the mouse is moved rapidly. This is fine. YOU ARE NOT REQUIRED TO CONNECT THE POINTS ON THE SCREEN.]
- There must be some way to quit the application from within the application itself. (Hitting Cntrl-C is not an option.)
- There must be some way to save the image currently displayed on the screen to a file within the application. The user should be able to specify the name of the file. You will need to use GLUI for this.
- Two extra features. This is your choice. Examples include: changing the color of the points being drawn, clearing the screen, allowing the user to specify the name of the output file, etc. These need not be complicated and need only demonstrate that you know how to use the appropriate user interface functions. One should utilize some interface ability using GLUT and the other using GLUI. Be sure to document what you used.
In all of the above cases, interaction between the user and the program should take place only through GLUT or GLUI functions. Entering data in the console window is not allowed.
In addition to the above requirements, you must also provide:
- Documentation - Briefly explain what your program does and how to operate it.
- An interesting image you created saved in JPEG format. This need not be a great work of art. The program saves files in PPM format. You will need to convert this to JPEG before turning it in. I recommend xv on Unix machines to do this, but anything that can make the conversion will work.
Turn in all your code, documentation, and image file using submit (on CS machines) or handin on CADE machines. Your code will be tested using whatever environment you turn it in on (CS or CADE). Your code should be written in C/C++ and compile using gcc/g++.
Resources
The templates to be used for this project:
- sketchpad.C - You must fill in the event functions. Provided for you is a global variable called canvas which is redrawn whenever the screen refreshes. The dimensions of this buffer are given by the defined variables WINDOW_WIDTH and WINDOW_HEIGHT. There is also a function save_raw_ppm_image() which takes a character string as its argument. The function saves canvas to a file with the name given in the character string argument. Since the file will be a PPM format image, it is recommended that you give the file the .ppm suffix. The sketchpad.C code is well commented and the places where you can add your own user interface code are marked.
- Makefile - Provided for your convenience. The libraries included by GLUT are already included the appropriate headers. Likewise, the file contains the appropriate information to link to the GLUI libraries. The Makefile contains instructions for compiling son Sun architectures in either the CS or CADE networks. Be sure to comment out the appropriate lines depending on where you are compiling.
Documentation for GLUT may be found here. Everyone will need to use GLUT for tracking mouse and keyboard events within the drawing window. It is also capable of simple menues as well as drawing simple shapes.
Documentation for GLUI may be found here. It is an example of a relatively simple graphical user interface builder. The libraries provided are for version 2 beta (which, despite its name, is fairly stable and bug free).
Final Notes
This section contains any final notes regarding this project ether due to questions raised by students or discoveries of my own. I will send messages to the class mailing list announcing any notes or clarifications, but this will contain a digest of all such info. These notes will never change what is required in the project, but may clarify some formerly ambiguous points and so should be checked semi-regularly.
- GLUT has several ways in which to receive data from the user. Don't feel obliged to use them all. You will need to use the mouse event (for when the user clicks on the screen) and the motion event (for when the user drags the mouse across the screen) but you are not required to use the other functions. That said, I would suggest you at least look at how they might be used.
- On CS Suns, GLUI causes the line initfuncCalled = -7676776 to be printed to the screen whenever the drawing window is reset. Aside from being annoying, this has no other detrimental effects and may be ignored.
- Turn in all parts of the assignment electronically using the handin or submit commands. The project name is sketchpad.
I.e.: submit cs4961 sketchpad file1 file2...