Assignment # 1
Due Date: 2-11-2010
The purpose of this assignment is to familiarize yourself with
Visual Studio 2008 interactive development environment and to get
practice with Win32 API, MFC, and OpenGL (GLUT) programming.
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
polygons, rectagles, and/or straight lines in the window's client area
positions determined by user mouse actions and colors selected from the
menu bar by the user. (The code for api-ex is at
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
a popup menu with the items: "Polygon", "Rectange", and "Line", should
appear. After either drawing function is chosen, subsequent mouse
should allow the user to draw as many instances of the chosen figure
If the user selected "Polygon", subsequent left mouse button
clicks should identify each new vertex of the polygon to be drawn.
right mouse button click should provide the last vertex of the
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
assume that the maximum number of vertices in any polygon is 99.
If the user selects "Rectangle", one corner of the resulting
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
will be able to move the mouse in order to determine the position
the diagonally opposite corner of the rectangle. That point will
anchored and the rectangle drawn when the user releases the left
If the user selects the "Line" drawing function, a straight line
be drawn between the points specified by the user by the next two
mouse button clicks he/she makes. As in the case of polygons, the
should be able to continue to draw straight lines until the user
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
If the user selects the "Color" menu item, a popup menu with the
"Red", "Green", "Blue", "Yellow", "Magenta", "Cyan", and "Black"
appear. Selecting any of these should change the drawing color to the
selected so that any subsequent polygons or lines will be drawn in
color. For polygons both the border and the interior should be in
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
In this part of the assignment you are to create an MFC
to the "Sketch" application discussed in class and in the notes so
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
selected from the menu bar by the user -- just as in Part A. (The code
the CView-derived class in the "Sketch" application as at
Selecting "Sketch" from the "Drawing Function" popup menu should put
program into a mode in which the user can start sketching when the left
button goes down and stop sketching when it is released -- just as in
"Sketch" example program discussed in class. The color of the sketch
be the current drawing color.
The rest of the functionality of the program should be as described in
The program should be written in Visual C++ as an MFC single
application; the Visual Studio Wizards should be used in developing
as demonstrated in class. It is suggested that you put all of your code
CView-based class -- as we did in the "Sketch" example in class.
In this part of the assignment your are to create an OpenGL
draws a polygon with a random number of vertices. The program should
OpenGL GLUT library. You should pattern your program after the ogl-pgm1
discussed in class. (The code for that program is at:
The polygon should not be filled; its border color should be some color
decide on. After the polygon is drawn, some text should be displayed in
bottom part of the window's client area that gives the number of
the polygon that was drawn. That text should be black. The following
shows what the user should see on the screen. Notice that for this part
assignment there is no menu, and mouse/keyboard actions are ignored.
Hints: For each part of this assignment can use C stdio sprintf(...)
a string so that it includes the integer decimal value of the number
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
You should seed the random number generator so that each time the
you get a different random number of vertices. The following will
srand((unsigned)time(NULL). For rand() and srand(...) to work you
#include the sdtlib.h header file; for time(...) to work, #include
time.h header file.>
Warning: In Part C you may find that you get the following error
"error C2381: 'exit' : redefinition;_declspec(noreturn) differs in the
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
where the error occurred. You will notice two _CRTIMP
declarations. Just comment out the first one.
You should submit a CD with the executables and all the files needed to
each project. The easiest way to do that is to copy each entire
directory to the CD. You should also turn in a printed copy of the .cpp
files for the Win32 API project, the .cpp and .h files of the program's
class for the MFC project, and the .cc file in the case of the OpenGL