Computer Graphics (50:198:456/56:198:556)
Instructor: Suneeta Ramaswami
Office: 323 Business and Science Building
Telephone: (856) 225-6439
Fax: (856) 225-6624
Programming Assignment #1: 2D drawing and event processing
Due: 9/28/17 (by 11:55pm)
Problem Description: Canvas
Write a program that simulates a 2D canvas and draws
various 2D shapes.
The program draws in the following mode:
- F1: line mode (see demo) . Two mouse
clicks on the canvas define the two vertices of the segment.
- F2: triangle mode (see demo) . Three mouse
clicks define the three vertices of the triangle.
- F3: rectangle mode (see demo). Two mouse
clicks define diagonally opposite vertices of the rectangle.
- F4: circle mode (not yet included in
demo). Two mouse clicks define the center and radius of
the circle (the first mouse click is the center and distance between
the two points is the radius).
In addition, your program should accept the following commands:
- f: toggles fill mode
- r: toggles drawing color red/black
- g: toggles drawing color green/black
- b: toggles drawing color blue/black
- c: clears screen
- q/Q/escape: quits program
Demo: An executable hw1-mac is available under
Resources on Sakai, which will run on Mac OS X. (If you don't have a
Mac, you can run this on the Macs in the student lab in Robeson
Library.) Run it to get an idea of how the program behaves.
- Display a rubberband (dotted moving line
following the mouse point) when mouse button is held down during
appropriate time of drawing.
- Use a linked list to keep track of all your
shapes. If using C, use a generic linked list
with void*, if using C++, make sure you set up the
classes right for STL list. Do not use arrays.
- Keep track of all shapes, and be careful to draw
the shapes from back to front to show correct overlapping,
i.e. oldest shapes should be drawn first.
- When clearing, you should make sure that you
clean up memory also. That is, delete all current shapes and avoid
any memory leaks!
- Circles are not part of the GL basic
primitives. You can draw circles by dividing a circle into a certain
number of slices (triangles), i.e. use GL_TRIANGLE_FAN.
- If you are using multiple files, please
provide a Makefile.
What to turn in:
Upload the final version of your program on Sakai by 11:55pm on
September 28, 2017.