<>CS-460/560
Assignment # 1
Due Date: 2-11-2010
The purpose of this assignment is to familiarize yourself with
using the
Visual Studio 2008 interactive development environment and to get
some
practice with Win32 API, MFC, and OpenGL (GLUT) programming.
Part A
In this part of the assignment you are to modify the "api-ex" Win32
API application discussed in class so that it permits the user to
draw
polygons, rectagles, and/or straight lines in the window's client area
at
positions determined by user mouse actions and colors selected from the
menu bar by the user. (The code for api-ex is at
http://www.cs.binghamton.edu/~reckert/460/api-ex.html)
Specifically the menu bar should contain the following items:
"Drawing Function", "Color", "Clear", and "Quit". The First two of
these should be popup menus. When the user clicks "Drawing
Function",
a popup menu with the items: "Polygon", "Rectange", and "Line", should
appear. After either drawing function is chosen, subsequent mouse
actions
should allow the user to draw as many instances of the chosen figure
as
desired.
If the user selected "Polygon", subsequent left mouse button
clicks should identify each new vertex of the polygon to be drawn.
A
right mouse button click should provide the last vertex of the
polygon,
and it should then be drawn and filled with the current drawing color.
Finally a message indicating the number of polygon vertices should
appear along the bottom part of the window's client area. You
may
assume that the maximum number of vertices in any polygon is 99.
If the user selects "Rectangle", one corner of the resulting
rectangle
should be anchored in the place the mouse cursor is when the user
first presses the left mouse button. While the button is down the
user
will be able to move the mouse in order to determine the position
of
the diagonally opposite corner of the rectangle. That point will
be
anchored and the rectangle drawn when the user releases the left
mouse button.
If the user selects the "Line" drawing function, a straight line
should
be drawn between the points specified by the user by the next two
left
mouse button clicks he/she makes. As in the case of polygons, the
user
should be able to continue to draw straight lines until the user
changes
the drawing function.
For each of these drawing functions, you don't need to worry about
restoring the contents of the window's client area after an expose
event. In other words your program does not have to respond to
WM_PAINT messages.
If the user selects the "Color" menu item, a popup menu with the
items
"Red", "Green", "Blue", "Yellow", "Magenta", "Cyan", and "Black"
should
appear. Selecting any of these should change the drawing color to the
color
selected so that any subsequent polygons or lines will be drawn in
that
color. For polygons both the border and the interior should be in
the
currently-selected drawing color.
The "Clear" and "Quit menu item should work as in the example program.
The program should be written in Visual C++ as a Win32 API
Windows
application.
Part B
In this part of the assignment you are to create an MFC
application similar
to the "Sketch" application discussed in class and in the notes so
that, in
addition to sketching, it permits the user to draw polygons,
rectangles, and lines at
positions in the window's client area determined by the mouse and in a
color
selected from the menu bar by the user -- just as in Part A. (The code
for
the CView-derived class in the "Sketch" application as at
http://www.cs.binghamton.edu/~reckert/360/sketchvw_cpp.htm)
Selecting "Sketch" from the "Drawing Function" popup menu should put
the
program into a mode in which the user can start sketching when the left
mouse
button goes down and stop sketching when it is released -- just as in
the
"Sketch" example program discussed in class. The color of the sketch
should
be the current drawing color.
The rest of the functionality of the program should be as described in
Part A.
The program should be written in Visual C++ as an MFC single
document interface
application; the Visual Studio Wizards should be used in developing
the program,
as demonstrated in class. It is suggested that you put all of your code
in the
CView-based class -- as we did in the "Sketch" example in class.
Part C
In this part of the assignment your are to create an OpenGL
application that
draws a polygon with a random number of vertices. The program should
use the
OpenGL GLUT library. You should pattern your program after the ogl-pgm1
program
discussed in class. (The code for that program is at:
http://www.cs.binghamton.edu/~reckert/460/ogl-pgm1-cc.html)
The polygon should not be filled; its border color should be some color
you
decide on. After the polygon is drawn, some text should be displayed in
the
bottom part of the window's client area that gives the number of
vertices of
the polygon that was drawn. That text should be black. The following
diagram
shows what the user should see on the screen. Notice that for this part
of the
assignment there is no menu, and mouse/keyboard actions are ignored.

Hints: For each part of this assignment can use C stdio sprintf(...)
function to
format
a string so that it includes the integer decimal value of the number
of
vertices in a
polygon. You will need to #include the stdio.h file at the top of
your program. In
Part C, you can use the C stdlib rand() function to generate a
random number.
You should seed the random number generator so that each time the
program runs
you get a different random number of vertices. The following will
do that:
srand((unsigned)time(NULL). For rand() and srand(...) to work you
will
need to
#include the sdtlib.h header file; for time(...) to work, #include
the
time.h header file.>
Warning: In Part C you may find that you get the following error
message:
"error C2381: 'exit' : redefinition;_declspec(noreturn) differs in the
stdlib.h
file". This is bug a in Visual Studio when used with the GLUT.
When you click on
the error message, Visual Studio will take you to the place in the
stdlib.h file
where the error occurred. You will notice two _CRTIMP
_declspec(noreturn)...
declarations. Just comment out the first one.
You should submit a CD with the executables and all the files needed to
build
each project. The easiest way to do that is to copy each entire
project's
directory to the CD. You should also turn in a printed copy of the .cpp
and .h
files for the Win32 API project, the .cpp and .h files of the program's
view
class for the MFC project, and the .cc file in the case of the OpenGL
project.