CS 4731, C Term 2011 Homework 0: Practice with OpenGL (Not to be submitted)
The aim of this practice exercise is to get your feet wet in OpenGL. You will learn how to
install and set up your OpenGL system and perform a few simple, fun tasks. You
will mostly go through some readings from the book and type in an
accompanying sample program or cut and paste examples. Follow the instructions
and type in code carefully. Note that due to the large number of operating
systems and compilers out there, I cannot provide help on all
platforms. I will provide assistance on how to compile your code on
ccc.wpi.edu. You can develop on any platform with C/C++ and OpenGL, but it'll be
your responsibility to get it working and port your code when you are done.
I have created a Frequently Asked Questions (FAQ) file that contains
information that you may also find useful. The FAQ was compiled from
actual questions from students in CS 4731 over the years.
The CS 4731 students worked using OpenGL and compiled on ccc.wpi.edu so the discussion
of platform-dependent issues is useful for this exercise and also for some issues that
may arise in later projects so please bookmark this page. You can find the FAQ
HERE . So, here goes:
- Get and install OpenGL and GLUT: First, get and install OpenGL and GLUT on your
favorite platform. Click [ Here ]
for instructions on how to get and install OpenGL and glut on your favorite platform and get it
ready for the programs below. Note: that you can use any systems
for your projects, but I will provide help and guidance
primarily for the WPI CCC Unix machines. OpenGL libraries come
with most recent versions of Microsoft Windows and Visual C++. So, if you are running a recent version of
Windows and Visual C++, you may already have the OpenGL libraries you need. Here's a
a sample Makefile
that works on ccc.wpi.edu. The makefile assumes that your OpenGL source program is in a file called cs4731_hw1.cpp.
Change the names accordingly for your program. Here's a sample output from using the Makefile
> ls
cs4731_hw1.cpp Makefile
[emmanuel@CCCWORK2 sierp]$ make clean
/bin/rm -f proj0 cs4731_hw1.o
[emmanuel@CCCWORK2 sierp]$ make all
g++ -Wno-deprecated -I. -c cs4731_hw1.cpp
g++ cs4731_hw1.o -lglut -lGL -lGLU -L/usr/X11R6/lib -lX11 -lXmu -lm -o proj0
- Draw three dots: Read section 2.2 (page 47) of Hill book. Use the sample code in
figure 2.11 (page 51) of Hill book to write a program for drawing three dots to the screen.
Name the file appropriately and save it (E.g. HW1_ThreeDots.cpp).
Compile and run the program!!
- Sierpinski Gasket: Read example 2.2.2 (page 52) of Hill book. Use the following
shell of the Sierpinski gasket to write a program which draws
the Sierpinski gasket. The bodies of the GLIntPoint class, the random function, the drawDot function
(figure 2.7, page 48) and the Sierpinski function (figure 2.15) have all been omitted. Type them
in from example 2.2.2 and the appropriate figures in the text.
Compile and run the program!!!
To make your Sierpinski gasket prettier, in the for loop
in the Sierpinski( ) function, change the number of iterations from 1000 to 50000. Drawing point size should be set to 1
- Reading and drawing polyline files: Read section 2.3, especially example
2.3.2 on page 61 of Hill book to draw polyline files.
Using the following shell write a program to
read in a polyline file and draw it on the screen.
The body of the drawPolyLineFile function has been omitted. Type it
in from figure 2.24 on page 62.
Save and use the polyLine file dino.dat for your work.
The basic structure of a GRS file is:
Compile and run the program!!
Note: Make sure you read and understand the examples in the book
before typing in the examples.
mailto:emmanuel@cs.wpi.edu