Math 155A - Introduction to Computer Graphics - Spring 2005
Instructor: Sam Buss,  Univ. of California, San Diego

Project #0 - Learn to login and use Visual C++ with OpenGL and GLUT

Goals:  In this assignment, you get oriented, make sure your passwords work, learn how to access your files and use the lab PCs, how to use Visual C++, simple debugging techniques.  See the "Summary of Work" at the bottom of this document for a list of what you must do.

What to hand in:  If you successfully complete everything on this list by Monday, April 4 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 Monday you must contact me or the TAs and discuss your problems.

Turn in procedures (For Future Assignments)   Grading will be personalized and one-on-one with the TA or with Professor Buss.  Your program must run on the PC lab and compile and run under Visual C++.NET.   You must come into the PC lab and meet one us.  You will have to show your source code, run the program, and possibly make changes on the spot to your program and recompile as requested by the grader.  You must 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 you will be responsible for getting your system to work with Visual C++.NET, 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 B337 and B349 (they are the same room!).  If you preregistered in the course and have an Open Computing account you should get an account automatically.  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.
    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 40(??) MB of disk space in your course 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 course home directory files are stored on the server ieng9,  and you can also access from that Unix machine.  Your instructor and TAs have access to your course home directory, but not your My Document folder.

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 logout 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  Spring05SolarProjectZero.zip.  Extract these into a directory named Solar in your home directory. 
    If you have problems with Ultimate Zip, 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 which usually is more reliable and faster than Ultimate Zip.

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 "sln" (= ".NET Solution").  This starts the compiler. 
     To compile and link the program, pick the Build Solution option from the Build menu.  (Note that the Compile option will compile, but not link the program.)  The build can also be invoked Control-Shift-B.
     Hopefully, your compile and link worked without any error messages.   If there were error messages, you will need to fix something. If you get error messages about not being able to read files or about files being modified outside the editor could reflect these problems, check and make sure your files are readable and writable.
     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 Start from the Tools menu.  Alternately you may just press F5.  If all goes well, the program will run correctly for you!  Look for a small solar system to be animating in a window.

4. Modifying the program.  Now try customizing the program.
    First, open the file solar.c:  On the left window, select Solution Explorer.  Then find the file solar.c in the panel, under Solar, Source Files. Double-click solar.c, 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.  (Setting all three values to zero 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 a good 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"; or alternately, just click to the left of the line.)  A big red dot appears to indicate the presence of a breakpoint.
        b.  Run the program: it will stop at the breakpoint.  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 choose the "Watch 1" window instead of the "Auto" window to display variable values.  In the Watch window, you may enter variable names to keep a variable's value permanently on the screen.  You can also move the mouse over a variable to see its value.
        e.  Experiment with debugging, ask us or other students for help. It is great way to make programming easier.
       
f.   There are a ton of other features to the debugger.  Ask for help, or explore them on your own.
        g.  You need to be in Debug mode to use the debugger.  If you find yourself in Release mode, switch back to Debug mode.

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.  

Summary of work:  You should have completed the following tasks.

  1. Downloaded, compiled and run the Solar program.

  2. Experimented with different color values.  Understood how the values for Red/Green/Blue (RGB values) affect the color you see on the screen.

  3. Learned how to use the interactive debugger, including
    a.  How to set a breakpoint
    b.  How to single step through your code.
    c.  How to watch the value of variables as you single-step through the code
    d.  How to step into a function call.

  4. If not using the lab machines, learn how to transfer code to the lab and get it to work there under Visual C++.NET.