Rudy Rucker's CS 116A Computer Graphics I




Paintings & Links



Calendar                        Suggested Exercises

CS 116A Green Sheet, Fall 2003


Prof. Rudy Rucker, MH 213, 924-5147, How to email me.
Office Hours: M 12:30 - 2:00, T 1:30 - 3:00, W 12:00 - 1:30

Class meets 12:00 - 1:15 PM T and Th, MH 225
Midterm: Tue, October 14.
Final Exam: Mon, December 15, 9:45 - 12:00

This course will introduce computer grahpics using the Open GL library. We'll start with basics, then develop some graphics tools for lines, polygons, circles, and polyhedra. We discuss mouse and keyboard input, then introduce vectors and matrices for animation, clipping, and transformations. We'll use transformation to rotate elementary 3D shapes and to assemble 3D scenes from Open GL primitives. Next we discuss modeling shapes with polygonal meshes. Finally we explore methods of altering the view of a scene.

The programming environment will be C++ and OpenGL. Our graphics programs will run under Windows in small DOS-like GLUT windows, a little like Java applets. I recommend getting an inexpensive copy of Microsoft Visual Studio Version 6.0 or the slightly more expensive Visual Studio.NET. Possibly you can also get by with the GNU G++ program, though I myself haven't tried it. You must use C++ and not Java. If you have trouble with C++, or are rusty with it, you can find a quick review of C++ on this site. In any case, a lot of our code will really just be simple C programs with a main function and a few special procedure definitions by you. We will not be doing Windows programming, although those who want to will have that option.

The text for the course is:
F. S. Hill, Jr., COMPUTER GRAPHICS USING OPEN GL, Second Edition, Prentice Hall, 2001

This is too big a book to cover completely in one course. We will cover part of it in CS 116A and then probably, for those who are interested, continue on in the same book in CS 116B. We intend to cover Chapters 1 to 7 in CS 116A.

Although your computer will probably have gl.h, glu.h, opengl.lib and glu32.lib, it may lack the glut files. You can get these off the web from Instead of going to, you can also download Version 3.6 right here with glut.h, glut32.lib, glut32.dll. Or download Version 3.7 here.

You have to do the following with these three files that you get:
Put glut.h in your Visual Studio include\gl directory, like in
       Program Files\Microsoft Visual Studio\VC98\Include\GL
Put glut32.lib in your Visual Studio LIB directory, like in
       Program Files\Microsoft Visual Studio\VC98\Lib
Put glut32.dll in your Windows SYSTEM32 directory, like in

I think it is wise that the three files be from the same version of GLUT or you may have compatability issues. If you put one file on your disk, put the other two as well, otherwise you may have different versions and you will get weird runtime error messages. Another posible cause of difficulty is if you have glut.dll or glut.lib anywhere on your hard disk, as these were designed for use with SGI machines, not Windows machines. The "32" means "Windows" in this context, so only use glut32.lib and glut32.dll.

Also be sure that your Visual Studio Project | Properties | Link | Object/Library Modules has these three libraries (type them in if not present, and do for Settings For: All Configurations).
glu32.lib glut32.lib opengl32.lib

You can download a ZIP file with C++ source code for many of Hill's examples from a page off his book website

The OpenGL Programming Guide also known as the Red Book. (Addison Wesley) is also useful. You can buy this or you can also read it online at this site. The "Red Book" is like a textbook, while the "Blue Book" is like a reference manual.

Grades will be based on homework (~100 pts), on the midterm (~80 pts), and on the final (~100 pts).

Assignments are due at the START OF CLASS on the due dates. Homework is marked down 20% if late one class, 40% is late two classes, and isn't acepted after that. WARNING: Skipping a homework assignment can sometimes lower your final grade by as much as a full grade point.

Cheating policy: Copying on an exam will result in a score of 0 on that exam for both parties.

Hmwk 1. 20 Points. Due Sept. 9, Tuesday.

(Mechanics 2 pts) (a) Give me a 2 pocket folder (b) put a piece of paper in it with your name, names of the programs, description of the controls, (c) give me a floppy disk or a CD with he three *.EXE files in the root, also the two *.DAT and the current glut32.dll that you use on your machine to run these. (You can find it in your windows\system32 directory). Make a SOURCE directory with the source code. Clean the source code using clean.bat.

(1 - 7 pts) Get and build Rucker's RectFlurry project, then tweak it to (a 1) draw black edges around the rectangles (b 1) draw the first (back) rectangles larger (c 2) draw the first (back) rectangles bluish, the middle ones greenish, and the front ones reddish yellow (d 1) add functionality so that the 'a' key turns autoanimation on and off, and have it start up with autoanimation off. Call it RECTLAND.EXE.
(e 2) the more that your scenes resemble landscapes the better. Consider using shapes other than rectangles to make this closer to being true.

(2 - 8 pts) Get Rucker's Lissajous project. Make the following improvements:
(a 2 pts) Have the x and X keys reduce and increase the xfreq by steps of 1, though don't go below 1. Have y and Y do the same for yfreq.
(b 0 pts) The way the code is written now, startt will eventually get too big. Put in some code to wrap startt around back to 0.0 when it reaches 2.0 * PI, this should not affect what you see on the screen.
(c 1 pts) It doesn't look nice to have the black lines touch the red frame. Make the black lines not quite reach out to the red frame, but leave the red frame visible.
(d 3 pts) Instead of drawing the trail of the pendulum as a simple black line, draw it as a ribbon which you create as a GL_QUAD_STRIP. 1 pt if it works at all, and the 2 more pts if its pretty. Pick a nice width of the ribbon, maybe shade it from red at one end to blue at the other, maybe draw black lines along its outer edges (but don't draw all the triangle edges), or...? In order to make the GL_QUAD_STRIP, its useful to have the cVector class I've created, get the file which includes the Lissajous project plus the necessary class definitions to use cVector.

(3 - 5 pts) Work Hill's Figure 2_22 code into a program to load files of polyline data, which should be quite easy as he gives you I think the whole source code. Call it LINEFILE.EXE. This program should take a file name as a command line argument. Test it to read Hill's DINO.DAT file (2 pts), and create your own (small) FACE.DAT file to draw a face (3 pts).

Hmwk 2

(1) (8) Get the and tweak this code. Note that snowstorm2 had a problem with the STL library..(a) Use a deque of polygons (STL double-ended queue).. At each update remove the oldest polygon and add a new one. (b) Have the polygons be moving from hiz to loz with each update, start them out near hiz. When they reach loz, they get "stuck" and don't move any further. Still remove the oldest polygon and add a new one with each update. (c) For more credit have the polygons tumble as they fall, rotating around some randomly picked axis. (d) For still more credit figure out how to draw nice stellated polygons in OpenGL. (e) Make it beautiful. [See snowstorm_hints.doc for help.]

(2) (8) Draw a random group of seven "Tai Chi" or "yin yang" objects as described in the book in Exercise 3.7.1

(3) (8) Use our code to(a) draw a helix, (b) a toriodal helix as in Exercise 3.8.5 with a few keyboard controls to vary the tightness of the turn and the size of the torus. (c) try and draw a tornado helix, that is a helix like a screw, with increasing radius bottom to top.of 3D curves using the same technique. (d) consider a toroidal tornado helix...

Snowstorm links

snowstorm1.htm //source code listing //source code for build //final version

Hmwk 3 Due November 18.

HOORAY! I got my cAssembly working nicely at last, 8 PM, Tuesday, Nov 11. What was hanging me up was that I was using a conversion constant DEGREESTORADIANS and I'd defined it as PI/90.0 instead of PI/180.0. So whenever I'd think I was turning a right angle, I was flipping. Sheesh! See

I am tired of working on this homeowrk, so don't count on me for any more "free" code. You're on your own with the BUMP and the SNAKE. Be sure and try them and bring in questions if you have them on Thursday. Note that these won't look good unless you (a) set the normals and (b) enable the lighting.

(1) 8 pts. SNOWMAN. Use as prototype code. I made this simpler than the snowstorm code, we don't use the _attitude matrix anymore, just make straight gl matrix calls in the cPolyhedron::draw. Your assignment (a) change the cPolyhedron::randomize method so that it will randomize _innerradius, _bottomradius, _topradius, _height within reasonable ranges. (b) add an s/ S control to halve/double the numbers used for _slices and _stacks. (c) Add a new cPolyhedron _gluttype: SNOWMAN. In the cPolyhedron::draw method put cases for this two types, and have the SNOWMAN be three white spheres stacked on each other, with a cone carrot nose and two small dark icosahedra for his eyes. Add a keyboard control m/M so that you show only snowmen/All the various kinds of polyhedra. If you prefer you can do this problem by creating a cSnowman child class of cPolyhedron, though you'll have to declare cPolyhedron::draw to be virtual so you can overload it.

(2) 8 pts. CHEERLEADER. I got my cAssembly working nicely at last. Use the cAssembly class in for this one. Make a squad of at least three cheerleaders standing on the xy plane twirling batons, while rocking left and right in unison around their own z axes and possibly jumping up and down. Dont have them tumble towards the screen like in the molecules program, but other than that you can use this program as your start code. I now 't have this working, I have my code in the myshapes.cpp file, and if with the #define TESTCHEER commented into donuts.cpp you'll see a body and a spinning arm.

Use the cJackPart from the book for your baton. Make the tips red and the stick silvery. The cheerleaders might have bodies that are a tapered cylinders with a torus on top with a sphere on top of that. Their arms can betapered cylinders as well, and can stick straight out from the body. But you can make the cheerleaders more elaborate if you like.

(3) 8 pts. BUMP. Mesh problem. Create a height map terrain and display it. I recommend using a cMesh class as described in the moleuculemesh.htm handout. Note that I forgot to define the int size() method in the cFace class, but it should just return _vertexindex.size(). Your terrain is based on the formula

z = MAXZ * cos(x)*cos(y) / (1.0+x*x+y*y), with x and y ranging from, say, -2*PI to 2*PI.

Have a user control z/Z to change MAXZ. Put the eye in the position we used for the Lissajous 3D

Use a double loop to draw the mesh. You can caclulate the normals with simple cross products instead of using calculus, though calculus is better. As we discussed in class, the normal will be cVector(-dz/dx, -dz/dy, 1), though you have to call .normalize to make it a unit vector.

Have the n/N key toggle visible normals on and off. Draw the normals as unit length red lines sticking out of the surface. If you are using a display a list, note that you will need to either have two display lists (one with normals and one without) or change the display list each time you turn normals on or off. Don't worry about n/N too much if you've already done this problem, it's only one point.

For full credit, animate this guy so the MAXZ oscillates up and down over time. Note that if you do this, it doesn't actually matter much if you have used a display list, as you need to keep rebuilding the list.

(4) 8 pts. SNAKE. Edit so that it draws snakes instead of ribbons. The idea is to put, say, an octagonal mesh waist every so often. Or a pentagonal "house" like we drew in class. We can orient this octagon to be in the plane of the normal and binormal of the curve. As in (3), you should put the mesh information into a cMesh. To make this problem simpler, you don't have to have the curve grow at one end and melt at the other, you can just draw the snake through one full cycle of the lissajous oscillation, that is, for t from 0 to 2*PI or possibly just 0 to 2*PI/A for some A relating to the freq params.

Have the n/N key toggle visible normals on and off. Draw the normals as unit length red lines sticking out of the surface. If you are using a display a list, note that you will need to either have two display lists (one with normals and one without) or change the display list each time you turn normals on or off.Don't worry about n/N too much if you've already done this problem, it's only one point.

Be sure to have the x/X, y/Y and z/Z still change the curve params.