CS312 Assignment 1: 2D drawing and event processing
Due: Thursday, Sep 8, 2016 (by the end of day)
Canvas [100pts]
Write a program that simulates a 2D canvas and draws various 2D shapes. This is an individual assignment.
The program draws in the following mode:
- F1: line mode (see demo)
- F2: triangle mode (see demo)
- F3: rectangle mode (see demo)
- F4: circle mode
- F5: polygon mode (extra credit)
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
Copy the executable hw1-mac or hw1-linux from /home/dxu/handouts/cs312 to your home directory, and run it to get and idea how this program behaves.
Please read the notes on asssignments here and follow instructions for submissions.
Additional requirements/hint
- 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.
- When in polygon mode, click of right mouse button will indicate the end of vertices for the current polygon. Consider how you can display non-convex polygons correctly, there is no easy solution.