CS 404: Lab 5: Adding Graphics with OpenGLGetting Started1. Boot into Linux. To do this, click on “shutdown” and then select“restart.” The computer will begin restarting. You will eventuallyhave the option to select either Win2K or Linux (use up and downarrows to switch, press enter to select).2. Open a web browser and go to the course website1. Download RAD1Dgl.tar.3. To unpack the tar-file, type tar xvf RAD1Dgl.tar in a terminal window.Cd into the direc tory “RAD1Dgl.”Adding Graphics to RAD1D1. Open the Make file. RAD1Dgl calls GLUT and OpenGL routines. Toget the code to compile, we need to use the -I option to tell the compilerwhere to find the header files for GLUT and OpenGL. We also need toset the LIBPATH to point to /usr/X11R6/lib (the library files for theX-Window system, Version 11, Release 6). Look at all the libraries! Ifour code only calls GLUT (libglut.a) and OpenGL (libGL.a), then whymust we call so many libraries?2. Type make to build rad1dgl. When you run it, it will ask you forthe usual command file, plus the number of time samples you want.Choosing “medium.cmnd” and “100” produces nice results. You mayalso specify both the file and number of samples on the command line(rad1d medium.cmnd 100). Run it a few times, play around with theparameters in the command file. Does adding graphics help you un-derstand the meaning of the various parameters?3. Now we’ll see how it all works. Open main.c in an editor and scrolldown to the subroutine main (at the bottom). Most of the subroutinescalled in main are in the GLUT library (they start with “glut”). Iwon’t go into all of the options available for these calls, but will tryto point out the general ideas. The first call, glutInit, tells GLUTto start up, and the second, glutInitDisplayMode, tells GLUT which1www.cs.cornell.edu/Course/cs404/2002sp1graphics model we want. GLUT RGB and GLUT DEPTH are the twosimplest possibilities. Another possibility is GLUT DOUBLE which“enables double-buffering,” a graphics model used for animation. Afterwe set up GLUT, we create a window by describing its initial sizeand position. We then register the two callback functions: DrawC forgeneral drawing, and ResizeIt to handle window resizing. We then callthe routine InitGL (in GLout.c) which initializes OpenGL. InitGL setsthe background color of the window to black and s ets-up a standardview for 2D data. Finally, we call RAD1D, and when it finishes, weturn control over to GLUT by calling glutMainLoop. This is all prettystandard stuff. The best way to get started with OpenG L and GLUTis to find some sample code (like this, or check out www.opengl.org)and change it to fit your needs–that’s what I did!4. Scroll up and look at RunRad–it should look familiar. Find the startof the main while-loop. At the start of every iteration, RunRad checkswhether it is time to sample C. If it is, it calls the function AddSample(in GLout.c). Where is the data stored? Which routines do you thinkcan access this data? Does this seem like good programming?5. From the point of view of GL, RunRad’s only purpose is to get datafor the plot. Look at DrawC in GLout.c. DrawC takes our data andplots C(x, tj) vs. x at several time levels. The outer for-loop iteratesover the available time samples. For each one, we pick a color by givinglevels of red, green, and blue to the OpenGL routine glColor3f. Colorlevels range from 0.0 to 1.0. We then tell OpenGL that we’re going toplot a series of line segments. The points are placed using glVertex2d.When all the points are placed, we tell OpenGL we’re done with theline. How are the points specified? What do A, B, C, and D do?6. It is tempting to think that DrawC produces some static picture. Put aprint statement inside DrawC (something like printf(”In DrawC\n”);)to let you know when you’ve entered that routine. Rebuild and run.Trying moving the graphics window around, minimizing it, movingother windows in f ront of it, etc. When does DrawC get
View Full Document