Rudy Rucker's CS 116B Computer Graphics II




Paintings & Links




CS 116B Green Sheet, Spring 2004


Prof. Rudy Rucker, MH 213, 924-5147, How to email me.
Office Hours:
T, Th 12:00 - 1:30
T, Th 4:15 - 5:00

Class meets T, Th, 10:30 - 11:45 AM, MH 225
Midterm: Thursday, March 25
Final Exam: Friday, May 21, 0945-1200

Latest Info

April 15, 2004----------------------

Ray tracing links. These are by an ace New Zealand programmer named Nick Chapman (a.k.a. "Ono-Sendai" after the cyberdeck brand in William Gibson's Neuromancer).

The first link is to Chapman's real-time raytracer. Get the demo 1.2 from this page, it's an amazing executable. Be sure and look in the readme doc for info about the controls. He has some source code here, but not the complete buildable source. Nick says the code is so optimized that it would be exceedingly hard to read and learn from. And, quite reasonably, he probably doesn't quite feel like giving this incredible hack away.

The second link is to Chapman's simple raytracer. You can get the complete buildable source of Version 1.0 from this page.
Or you can get a very slightly altered version of Nick's Simple Raytracer 1.0 source here from my page, I'll call it version 1.01.
Nick Chapman's Simple Raytracer, Version 1_01
The (trivial) changes I made were to (a) pragma out some annoying warnings with a line in maths.h, (b) add a useful clean.bat file for removing junk files before zipping, (c) add a Visual Studio.NET *.sln project file to supplement the Visual Studio 6.0 *.dsw project file it comes with.

March 18, 2004 ----------------------

Check the Review for Midterm over the weekend, and bring in review questions on Tuesday.

March 11, 2004 ----------------------

Download all the Red Book 1.4 Sample Code.

We'll be talking about some Bezier code. Here's a build of the three Red Book Bezier examples, with a Visual Studio project.

March 9, 2004 ----------------------

SGI files for using OpenGL 1.2, 1.3, 1.4 and extensions. (Jason Tong found this link.)

Bump Mapping tutorial by Paul Baker found by J. Tong. Download Baker's source code example to build (slightly tweaked to build on vanilla windows machine.)

Some users have reported getting stripes when doing alpha blending. Possibly there could be a fix in this "sorting" trick found in alphablend.c at the SGI Advanced97 site

A similar approach might help if you have stripes in a big textured rectangle, the rectangle might be z-fighting with its back side.

/* draw the front and then the back faces (essentially sorts the
polygons). */


Feburary, 2004 ----------------------

Latest build of Pop at the game site is 35.2, if your'e interested. This fixes most of the bugs the CS 240 students found. Also I found a way to get OpenGL 1.2, 1.3 and extensions to work (yes, Windows still ships with OpenGL 1.1 ONLY --- are you suprised?) But there's a simple workaround, just include a file called glext.h from SGI. And now our critters have delayed specular lighting, which means they look nicer! PickNPop is well again, too.



To get Visual Studio.NET 2003.

(1) Get a random "Student ID" in class from Rucker.

(2) You can get the basic install disk CD1 for free at Washington Square Hall 1.

(3) Or, if you want the full install on CDs that you get to keep, you can order for $13.30 (includes shipping) from

At this site DON'T write your REAL student ID into the "Student ID" field. Instead use the random "Student ID" that Rucker gave you. For Password you can use anything you like, just make it easy to remember.

Get the Nate Robins Open GL Tutorials Right Away!

These are incredibly great executables with source that let you test all sorts of OpenGL combinations involving lights, materials, textures, fog, etc. Download Nate Robins Tutorials. I have the executables on the K drive as well, for use in the lab.


Hmwk 1. Due Tuesday, Feb 17, 2004

Fix: Insert the following two bold lines before the gluLookAt call in the setProjectionMatrix method in donuts.cpp. The comments explain why.

glMatrixMode(GL_MODELVIEW); /* I learned from David Lin
that I need to have the gluLookAt acting on the MODELVIEW matrix
and not on the PROJECTION matrix. It acts on whatever matrix is
active, as the OPenGL doc says, "The matrix generated by gluLookAt
postmultiplies the current matrix." Not having this line here
meant that our viewpoint calcuations were messed up and specular
highlights were in the wrong place when we put in
glLoadIdentity(); /* Clear out any old gluLookAt resuts from
the MODELVIEW matrix. */
gluLookAt(eye.x(), eye.y(), eye.z(), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

It may possibly be that you should NOT use ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE ); after all. In one demo I was seeing a confusing problem with it. If your highlights don't look righ with LOCAL_VIEWER on, turn it off, and put the eye out at the positive z axis with the lights more or less behind you, and then it should look OK. But if the LOCAL_VIEWER doesn't seem to be hurting, leave it in.

Overview: I want you to design and implement four classes: cColor, cLight, cLightingModel and cMaterial, and then use these with the demo program to create two demo programs involving lighting. You will hand in (1) printouts of your (a) cColor, (b)Material, and (c) cLight class prototypes (they can live in a single file with a name like lighting.h and be implemented in lighting.cpp), nicely formatted, (2) a FUNKYDONUTS.EXE executable, (3) a SPECULAR.EXE executable.

Note that you don't REALLY need the cLight or cLightingModel class for this problem, but the cMaterial class will be quite useful. You should work on your apps at the same time as you develop the classes in any case.

I built a fresh molecules demo that doesn't start out with the "gun-turret" shaped cheerleader. I still need to add a .NET project file. I put the viewer up in the positive octant. I make the lighting model better and improved the comments on the lights. I got rid of an old bug where we were specifitying the viewer "up" to be the Z axis, when we really want it up to be the Y, and the old viewer was confused and put -Y for the up. I also commented in ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
which seemed to beimportant if your viewer doesn't happen to be at, like (0,0,z) looking towards -z. If you built your SPECULAR program without this switch turned on and with the old molecules 3, the highlights will be on the back of the balls. The new fix in setProjetionMatrix will make this better as well.


(1) (a) class cColor : public cVector inherits from our cVector class but it has an extra _alpha field. Although it has the same Real _x, _y, _z fields as cVector, we'll have mutators with color names, like Real red(){return _x;} and accessors with color names, like void setRed(Real r){CLAMP(red, 0.0, 1.0); _x = r;}, where CLAMP is a macro I defined in realnumber.h. Or you could block copy the cVector code and rewrite from scratch. We will also have a static cColor method randomColor() that uses a method from the cRandomizer class. And a member void setRandom value to randomize a color, possibly with some args about the brightness range. These shouldn't change the alpha which we normally set separately I think we need glSetVertex() and maybe a glSetMaterial(...) as well. Or, maybe better, simply a copyTo(Real *valarray) method that copies the r,g,b,alpha into a valarray that can be used by opengl calls.

(1) (b) class cMaterial should have, I think, the following fields. cColor _ambient_rho, _diffuse_rho, specular_rho, specifying the reflectivity relative to the three types of light, also a Real _alpha field for transparency (possibly more transparency fields will be used later on), also a Real _specular_exp or, if you like, _shininess, for the specular exponent, also a boolean _smoothing_onoff. We'll need a some randomizing methods, also some methods for putting normal useful values into the fields. By default always put some shade of gray for the _specular_rho. Usually _ambient_rho and _diffuse_rho should be the same, but in this demo we can play with having them different. Avoid having any 0 fields in the cColor slots, as then you don't pick up color from lights. Look at p. 423 of the book for inspiration. And we'll need a glSetMaterial method (same name as the cColor::setMaterial(), but it does more).

(1) (c) class cLighting needs a cVector _position, a boolean _isatinfinity, cColor _ambient_intensity, _diffuse_intensity, specular_intensity, and a boolean _onoff. We'll need some spotlight fields, too. OpenGL interface methods will include glInstall() and glEnable(boolean onoff). Maybe some more methods.

(1) (d) LIghitngModel needs several fields as well.

(2) FUNKYDONUTS.EXE Give each cAssembly a cMaterial *_pmaterial field (pointer members are always better, but if you're scared of them, use a cMaterial _material field), and by default randomize the cMaterial to some reasonably diverse random values. Have four lights in the world, by default all will be on, but you can toggle them individiually with th 1, 2, 3, 4 hotkeys. The lights should be as follows
i) pure ambient, maybe (0.25, 0.25, 0.25), no specular or diffuse. Since it's all ambient, it doesn't matter where you put it, so just put it at the origin.
ii, iii, iv) The other three lights will have 0 ambient intensity, only diffuse and specular. Each will use the similar diffuse and specular color, though maybe one is stronger than the other, and they will be, respectivley, mainly red, mainly green, and mianly white. Cahnge these specs if you like. Position the lights anywhere you like --- the bottom line is that the demo should look as interesting as possible, with nice highlights on the smoot things and clearly distinguishable faces on the polyhedra. Also consider whether to make them positional or directional. Tell me on a piece of paper where the lights are.
As well as the 1,2,3,4 hotkeys and the default molecules5 hotkeys add a g hotkey. Have the g (for go) key step through a sequence of different shapes so you can compare the materials better, have the order be sphere, cone, torus, teapot, tetrahedron, icosahedron, and possibly a bonus shape like maybe an old snowman or cheerleader.
Have the s key toggle smoothing on and off.

(3) SPECULAR. The goal here is to reproduce figure 8.15 in our textbook, see pp. 419-419 for a description. But I'd like to see colors. Have the objects not moving through space, just sitting still or possibly rotating on their individual axes. As in FUNKYDONUS, have the g (for go) key step through a sequence of different shapes so you can compare, have the order be sphere, cone, torus, teapot, tetrahedron, icosahedron, and possibly a bonus shape like maybe an old snowman or cheerleader. In this program have the objects material be gray colored to facilitate comparision, but have colored lights. Have the s key toggle smoothing on and off. Use the same material for all the objects, probably just some kind of gray. I think keep same colored lights as before, maybe drop the ambeitn light. We can discuss this a bit more. It will proably look better with ::glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE ). The new fix in setProjetionMatrix will make this better as well.

Hmwk 2. Due Tuesday, March 9.

Get Merge your (or someone else's) color, material, and light code into this build. Maybe change cMaterial to include a texture pointer or texture id , and maybe call the texture select inside the cPolyhedron::draw. Maybe give cPolyhedron an int _texturename for it to select if _usestexture is true. A polyhedron should set its material to all white if it has texture. Use the GL_MODULATE mode of texture not the GL_REPLACE mode --- then the diffuse and ambient light color get blended with the texture color. Be sure to leave on the call to delay specular color till last.

Hand in a single executable MYTEXTURE.EXE that has textures on all the objects and which runs in two modes: scary and happy.

(1) Shows tumbling shapes like in texture2, but now we have texture on the toruses and all the polyhedra.

Edit myglutshapes.cpp so that torus, tetrahedron, icosahedron, dodecahedron, and octahedron have texture coordinates.

Figure out why filigree.bmp doesn't work. Make some new image files.

(2) By default make the tunnel look scary and cyberpunk with dirty walls and aliens and lights on the ceiling.

(3) And have the 'h' for happy switch changn the tunnel to be cheerful and cute and happy. If you prefer, your program can start in the cute happy mode and 'h' switches to the scary cyberpunk mode.


Hmwk 3. Alpha Demo on Tuesday, May 4.
Final Demo on Thursday May 13.

The has the latest changes we discussed in class. Use this code as a starting point to get mouse control of viewer, billboarded textures (with transparent backgrounds), modulated lighting on textures combining specular highlights with texture. Also try and have lights with spotlight, attentuation, or motion effects. Possibly use some alpha transparency.

Overall mission: make a demo that's "as good as a Superbowl commercial" or, "a billboard on Sunset Boulevard in Hollywood."

Call your executable (???)final project CS116b, May 2004.exe where (???) is an informative name like "Bongo Fury" Or call it something else. The main thing is HOW GOOD IT LOOKS. Put a lot of effort into adjusting your lights, your camera position, your textures. I prefer that you use some cAssembly objects that are composites of primitive polyhedra. Also you may want to use undulating meshes.

Hand in a CD with executable and all support files in the root (test that it runs from the root!).

Put your source files in their own directory.

Give me a printed sheet with a description of the controls.

Final. Friday, May 21, 9:45-12:00

Non-credit extra: If you feel like it, merge your final project with so you can make a demo version that includes your programmed keystrokes. This is non-credit, and you can postpone it if you like. I'll eventually post the best demos on this page.