CSE 167 - Introduction
to Computer Graphics - Fall 2003
Instructor: Sam Buss, Univ. of California, San Diego
Project #0 - Learn to login and use Visual C++
Goals: In this assignment, you get oriented, make sure your passwords work, learn how to access your files and the public course files, how to use Visual C++, simple debugging techniques.
What to hand in: If you successfully complete everything on this list by Friday, October 3, you do not need to do anything further. We will assume you have been successful in the assignment. If you have problems and cannot complete the work by Friday you must contact me or one of the TAs and discuss your problems.
Turn in procedures: Grading will be personalized and
one-on-one with a TA or with Sam Buss. Your program must run on the PC
lab, you must come into the PC lab and meet one us. You will have to show
your source code, run the program, possibly make changes on the spot to your
program and recompile as requested by the grader, and be able to explain how
your program works and why it renders what it does.
If you want to work on your home machine or other machine: OpenGL will run on many environments, including linux, unix and macintosh. You may do development on other machines, but will be responsible for getting your system to work with OpenGL, plus, you must transfer everything back to the PC lab for grading purposes. If OpenGL or GLUT is not installed on your machine, you will need to download the header files, library .lib files and dynamic library .dll files. See the "Graphics resources on the main course web page for help on where to find these.
Logging in: The PC lab for this course is in APM 2444.
If you preregistered in the course and have an Open Computing account you should already have an account. If you are adding the class
and do not have an Open Computing account, you need to get
course account cards from me that you take to ACS (second floor of APM) to get a
course account. [I am guessing on this based on how courses have worked in
When you log in, you will find a Class Resources directory on the desktop. Inside it are shortcuts (links) to your personal home directory, and to the public course directory. You should always save your files in your home or in your My Documents directory.
Disk space. You should have 20MB of disk space in your home account.. This may not be enough to hold a quarter's worth of work. In this case, you should go back and erase any folder named Debug or Release that was created by Visual C++ (but be careful not to erase your source files). Your home directory files are stored on the server ieng9, and you can also access from that Unix machine. Your My Documents folder should have 50MB of disk space available. Your instructor and TAs have access to your home diroectory, but not your My Document folder.
File recovery/backups: The file server is a sophisticated RAID system and does continuous backups (more-or-less). If you accidentally overwrite an important file, ACS may be able to recover it for you.
Logging out: Don't forget to log out when you are done. Otherwise, you leave your account completely unprotected!! By holding the SHIFT key down through the entire log out procedure, it will skip some steps and the logout will go faster.
FOR THIS PROJECT #0, DO THE FOLLOWING STEPS #1 - #6.
1. Downloading files for Project #0. Download the
Solar program from the zip file
Extract these into a directory named Solar in your home directory.
If you have problems downloading this zip file, you may instead copy the
Solar folder from the public directory.
If you have problems with Ultimate Zip (say, it hangs), try instead to download the zip file and save it. Then select it (right click) and choose Open With -> Compressed (zipped) folders. This uses the built-in Windows unzip code.
2. Running the Solar program: Go to the directory
Solar. Run the program Solar.exe. You should get
a window showing a simple solar system with a sun, earth and moon: with the
earth revolving around the sun and the moon revolving around the earth. You may use the
up-arrow and down-arrow keys to control the speed of the solar system.
In particular, use the down-arrow key repeatedly to slow down the animation so
you can see smooth motion. You may use the "s" key to single step the animation,
("s" = "step" or "stop") and the "r" to restart the animation ("r" = "run").
Experiment with the operation of this program.
Congratulations! You have just run your first OpenGL program.
3. Compile and execute the Solar program.
To start the C++ compiler and load the Solar project, double-click on the file with extension "dsw" (= "Development Studio Workspace"). This starts the compiler.
To compile and link the program, pick the Build Solar.exe option from the Build menu. (Note that the Compile option will compile, but not link the program.) The build can also be invoked by a icon on the second menu bar, or by just pressing the F7 command key.
Hopefully, your compile and link worked without any error messages. If there were error messages, you will need to fix something. One thing that might have gone wrong is that you are using the dsw file from the Public Folder, or you neglected to make your files readable (any error messages about not being able to read files or about files being modified outside the editor could reflect these problems). [If you are working from on a machine at home, you need to be sure you have the OpenGL and GLUT header files, library files and dll's.]
Once the file Solar.exe is built, you can run it by selecting Execute (or Go) from the Build menu. Alternately you can use the Execute or Go icon on the second menu bar, or you may just press F5. If all goes well, the program will run correctly for you!
4. Modifying the program. Now lets try customizing the program.
First, open the file solar.c: On the left window, select File View. Then find the file solar.c in the file view, and double-click it, to open it for editing.
Then, find the line glColor3f(1.0,1.0,0.0); which sets the color of the sun. Replace this by glColor3f(1.0,1.0,1.0 ). (The last 0.0 changed to 1.0.)
Recompile and run the program. The sun should now be white.
Try changing the color of the earth or the moon. Find the appropriate glColor command --- its three arguments are the Red, Green and Blue components of the color. Try setting different values for these colors. (Three zero values will be black and hence invisible.) Recompile and run the program.
Congratulations, you now know how to edit, compile, link and run OpenGL programs!!
5. Learn to use the Visual Debugger. If your only
programming experience is under Unix you owe it to yourself to learn how to use
an interactive visual debugger. Visual C++ is one of the best ones around
(although most commercial development products are also quite good).
You should learn at least the following:
a. Insert a break point: Find the line that says if (spinMode). Insert a breakpoint, by placing the cursor on that line and pressing F9 (or right-click and select "insert breakpoint".
b. Run the program: it will stop at the break point. If you look in the window at the bottom left, it shows the values of current variable (such as spinMode, HourOfDay).
c. Single step through the code. Press F10 (or choose Step Over off the Debug menu). The program goes to the next line. Note how the variables in the bottom left window change and their values change too. Try pressing F10 again: see what happens. Repeat.
d. There are more features learn. The most important are (a) Step Into and Step Out -- unlike Step Over, Step Into let the debugging step inside function calls. Step Out runs until the end of the current function and stops at the point where it returns. (b) The Watch Window You can enter variable names into the bottom right window and keep a variable's value permanently on the screen.
e. Experiment with debugging, ask us or other students for help. It is great way to make programming easier.
6. If you are using machines other than the APM lab you are not done yet: Verify that you can move code from your working machine to the PC lab, and that it will compile and run on the PC lab machines.