*This is a summary of the lectures from ECSE-4750 Computer Graphics, Rensselaer Polytechnic Institute, Fall 2011. It is intended to be easier to read than the separate Piazza entries. It is also available for indexing and searching.*

I will add links to any handwritten notes later. Until then you can use the links in the piazza entries.

# Quick links

- Course home page
- Lectures, summarized on one page.
- Piazza.
- Google calendar.
- textbook.

# Loading...

**Week 1**

## Wed 8/31 (L1)

- Discuss syllabus
- Introduce piazza.
- Show
- Show simple OpenGL program, square.cpp, from the code zipfile on the publisher site.

## Thurs 9/1 (L2)

- Notes written on the viewgraph are here. However you had to be there to really understand them.
- We dissected our initial OpenGL program: square.cpp, to understand every line. We made many small mods, recompiled and executed it. square.cpp is in the code zipfile on Guha's web site.
- We saw part 2 of the history of graphics.

**Week 2**

## Wed 9/7 (L3)

## Linear algebra tutorial

- For students confused by the linear algebra questions, the following may help:
- Also see wikipedia.
- Some older graphics texts have appendices summarizing the relevant linear algebra.
- The scalar (dot) product is needed to do things like this:
- compute how a ball bounces off a wall in pong
- compute lighting effects (how light reflects from a surface)

- The cross product's applications are mostly in engineering, e.g., to compute torque and angular momentum.
- The triple product (A.BxC) computes the volume of a parallelepiped.

## Thurs 9/8 (L4)

- Handwritten notes during lecture.
- hemisphere.cpp shows
- rotation and translation
- perspective projection

- circularannuluses.cpp introduces the depth (or Z) buffer. With it, the nearest object on each pixel is displayed. W/o it, the last object drawn into each pixel is displayed.
- squareannulus*.cpp show more efficient ways to plot lots of vertices.

**Week 3**

## Mon 9/12 (L5)

On Wed, just a lab for people to get final help on the homework.

Today:

- squareAnnulusAndTriangle, p 69: interspersed vertex and color data
- helixList.cpp:
- display list
- push and pop transformation

- multipleLists.cpp: multiple display lists
- fonts.cpp, p 72: bitmapped and stroke fonts
- mouse.cpp: mouse button callback
- mouseMotion.cpp: mouse motion callback
- moveSphere.cpp, p 76: non# ASCII key callback

## Wed 9/14

Today is a lab to get help for homework 1.

## Thurs 9/16 (L6)

- Videos
- Programs
- menus.cpp - p 77
- lineStipple.cpp - p 77
- canvas.cpp - p 78
- glutObjects.cpp - p 80
- clippingPlanes.cpp - p 82
- viewports.cpp - p 86
- windows.cpp - p 87

**Week 4**

## Makefile

LDLIBS=-lglut -lGLEW -lGLU -lX11

## Mon 9/19 (L7)

- Video
- Programs
- reviewed the attached modified simple drawing program canvas2.cpp
- new programs from the book:
- glutObjects.cpp
- 9 builtin glut polyhedra
- initial look at lighting in OpenGL; we'll see this a lot more

- glutObjects.cpp
- clippingplanes.cpp: add more clip planes to the 6 original ones (the sides of the view volunme)
- viewports.cpp: change the viewport and draw more stuff
- windows.cpp: multiple top level windows, each with its own callbacks

- Next Mon, we start chapter 4; so feel free to read ahead. We'll see the mathematics of transformations. Each of the major transformations (translation, rotation, scaling, projection) can be expressed as a multiplication with a 4x4 matrix.

## Wed 9/21

A lab only for homework questions.

## Thurs 9/23

No lecture.

## Visible human

A few days ago I mentioned the Visible Human project, where a male and a female corpse were sectioned and scanned. This is the site.

Googling will produce other info about it.

**Week 5**

## Mon 9/26 (L8)

- Videos
- Topics today
- box.cc, p. 92, with lots of the mods
- section 4.2 Composing Modeling Transformations

## Wed 9/28

A lab to get help from TAs on the homework.

## Thurs 9/29 (L9)

- Videos:
- New Material: Guha, starting at page 114
- New ideas
- translation as a 4x4 matrix multiply
- animate by setting an idle callback or a timer callback

- Programs
- composeTransformations.cpp
- box.cpp with blocks 10 and 13 inserted (separately, not both at once)
- rotatingHelix{1,2,3}.cpp

- Handwritten notes during lecture

**Week 6**

## Mon 10/3 (L10)

- Video
- Code
- ballAndTorus.cpp, p 120

- experiment 4.20, p 122
- ballAndTorusWithFriction.cpp, p 124
- clown head, p 125
- flowerintPoint.cpp, p 129
- viewing transformation, p 133
- spaceTravel1.cpp, p 153

## Wed 10/5

This lab is just a chance to ask homework questions.

## Thurs 10/6 (L11)

- Steve Jobs
- Code
- animateMan1.cpp etc, p 157
- ballAndTorusShadowed.cpp, p 161
- selection.cpp, p 163

- 10/13 Exam
- Open book, open notes
- Questions based on the programs and material covered in class
- I'll be at the Wed lab to answer questions.

**Week 7**

## Tues 10/11 (L12)

- Videos: Siggraph 2009 stuff
- Code: picking and selection
- Handwritten notes: here.

## Wed 10/12

review before exam

## Thurs 10/13

- open book, open notes, no computers

## Mon 10/17 (L13)

### Broader impact of the 36 graphics programs that we've studied

Beyond the specifics of OpenGL, they show one way to design an interactive graphics API. The ideas that you've seen - event loop, transformations, viewing, etc - occur in any graphics system.

### Term Project

See here.

The proposal was due this Thurs, but you can submit it on next Tues.

*Size of term project:* It's impossible to specify how many lines of
code makes a good term project. E.g., I take pride in writing code that
is can be simultaneously shorter, more robust, and faster than some
others. See my 8-line program for testing whether a point is in a polygon
here.

- According to
*Big Blues*, when Bill Gates was collaborating with IBM around 1980, he once rewrote a code fragment to be shorter. However, according to the IBM metric, number of lines of code produced, he had just caused that unit to officially do negative work. - Some winners of ''The International Obfuscated C Code Contest
(IOCCC)'', http://www.ioccc.org/, implement graphics projects in
amazingly short programs. My local cache is here:
ioccc/. Note the beautiful formatting of many programs.
- gavare.c is a 28 line ray-tracing program producing this: gavare.jpg (as a pnm file).
- vik1.c is a 63 line interactive color auto racing program.
- banks.c is a 60 line interactive flight simulator.
- eldby.c is a 8 line flying spheres program. However its graphics is pretty primitive.
- williams.c is a 73 line missile command game.
- dodsond1.c is a 72 line Othello game, which beats me.
- buzzard.c is a 31 line 1st person maze walker with perspective display.
- tvr.c is a 115 line interactive fractal program that puts up 2 X windows.

### New material

We now switch to more math and less programming. We'll do it a little differently from Guha.

- Transformation review
- Each type of common transformation (translate, rotate, scale, project) is a matrix.
- If applying several transformations, it is faster to first multiply the matrices, then just multiply all the points by that one matrix.
- Most OpenGl transformation routines modify one of two current transformation matrices: the modelview or the projection.
- The modelview matrix moves the world so that the camera is where you want it, relative to the objects. Unless you did a scale, the transformation is rigid - it preserves distances (and therefore also angles).
- The projection matrix view-normalizes the world to effect your desired projection and clipping. For a perspective projection, it does not preserve distances or angles, but does preserve straight lines. We'll cover this later.
- The last transformation catenated onto the current matrix is the first transformation applied to the object.
- OpenGL combines the two matrices, so the modelview matrix is applied first to the object.

- Rotations:
My note on 3D rotation
- all rigid transformations in 3D that don't move the origin have a line of fixed points, i.e., an axis, that they rotate around.
- deriving the vector formula for a rotation given the axis and angle
- computing the matrix from a rotation axis and angle
- testing whether a matrix is a rotation
- if it is, then finding the axis and angle

## Thurs 10/20 (L14)

- Quaternions. This is an alternative method to
rotate in 3D. Its advantages are:
- It starts from the intuitive axis-angle API.
- Animating a large rotation in small steps (by varying the angle slowly) is easy. In contrast, stepping the 3 Euler angles does not work well, and there's no obvious way to gradually apply a {$3\times3$} rotation matrix, {$M$}. (You could compute {$M^{1/100}$} and apply it 100 times, but that computation is messy.)
- When combining multiple rotations, the axis and angle of the combo is easy to find.
- Having only 4 parameters to represent the 3 degrees of freedom of a 3D rotation is the right number. Using only 3 parameters, as Euler angles do, causes gimbal lock. That is, you cannot always represent a smooth rotation by smooth changes of the 3 parameters. OTOH, using 9 parameters, as with a matrix, gives too much opportunity for roundoff errors causing the matrix not to be exactly a rotation. (You can snap the matrix back to a rotation matrix, but that's messy.)

- Photos of what I wrote on the viewgraph.

## Forbes compares Engineering and Economics

http://www.forbes.com/sites/billfrezza/2011/10/18/the-fundamental-fallacies-of-macroeconomics/

*Do you sometimes wonder why economists are accorded such respect and influence given the fact that they claim knowledge over the unknowable, promote theories that are untestable, and make forecasts for which they are never held accountable? Isn't that the definition of a witch doctor?*

*If engineers were held to the same standards, bridges would collapse as often as banks, planes would fall from the sky (if they ever got off the ground), and cyclical blackouts would be a permanent feature of our electrical grid. But at least they would get to visit the White House.*

*Have you ever watched engineers from different schools argue on Sunday morning talk shows about the validity of Bernoulli's Principle or Ohm's Law? No? Yet economists, like rival witch doctors, get red in the face promoting diametrically opposed economic remedies, sometimes sharing Nobel Prizes in the same year for theories that directly contradict each other. Take $2 trillion and call me in the morning.*

## Possible spring courses

For students who want lots of graphics. These courses won't overlap.

- CSCI-4530/6490 ADVANCED COMPUTER GRAPHICS, T F 2:00 3:50PM Cutler See the description in piazza (I'll copy it over here later.)
- CSCI-4973-01 INTRO TO VISUALIZATION W 10:00 11:50AM Cutler
- ECSE-6800 ADVANCED 3D COMPUTER GRAPHICS AND VIZ, M R 4-5:20 Franklin This course will spend a month each on 4 topics related to advanced graphics.

## Mon 10/24 (L15)

- Videos
- http://www.youtube.com/watch?v=rrUCBOlJdt4&feature=related Gimble Lock - Explained

- View normalization or projection normalization
- We want to view the object with our desired perspective projection.
- To do this, we transform the object into another object that looks like an amusement park fun house (all the angles and lengths are distorted).
- However, the default parallel projection of this normalized object gives exactly the same result as our desired perspective projection of the original object.
- Therefore, we can always clip against a 2x2x2 cube, and project thus: (x,y,z)->(x,y,0) etc.

- Copy of what I wrote on the tablet.

## Wed 10/26

A lab to resolve grades.

## Thurs 10/27 (L16)

- Homework 6 is out.
- Homogeneous coordinates This is today's big idea HomogeneousCoords
- Lighting

This is the next topic. To prepare, read Guha, Section VI, pages 403-524. (You don't have to read *all* of it for Mon.)

Things I added to lecture, which are not in the book:

- Tetrachromacy
- metamers
- CIE chromaticity diagram
- Job ad: Database Programmer "We are seeking at least one undergraduate or master's student in the database area. The ideal candidate will have completed at least one undergraduate course in database systems. Good written and oral communication skills are a plus. This position provides an opportunity to work within the EMPAC facility, and to support demos and user studies with emergency response personnel in the Albany region. The position would begin immediately, and would involve approximately 10 to 15 hours of work per week during the semester, with an option for further time during summer. Compensation is competitive. If interested, please send a short memo describing your experience to Professor David MendonÃ§a (mendod@rpi.edu). "
- Copy of what I wrote on the tablet.

**Week 10**

## Mon 10/31

- Continue lighting, mostly following Guha.
- Copy of what I wrote on the tablet.

## Wed 11/2

A lab to discuss homework 6.

## Thurs 11/3

No class.

Homework 7 online, due next Thurs.

**Week 11**

## Mon 11/7

- Quick review of the Phong lighting model. The total light at a pixel is the sum of
- Incoming ambient light times ambient reflectivity of the material at the pixel,
- Incoming diffuse light times diffuse reflectivity times a factor for the light source being low on the horizon,
- Incoming specular light times specular reflectivity times a factor for the eye not being aligned to the reflection vector, with an exponent for the material shininess,
- Light emitted by the material.

- That is not intended to be completely physical, but to give the programmer lots of parameters to tweak.
- OpenGL has several possible levels of shading. Going down the list makes the shading better but costlier.
- Shade the whole polygon to be the color that you specified for one of the vertices.
- Bilinearly shade the polygon, triangle by triangle, from the colors you specified for its vertices.
- Use the Phong lighting model to compute the color of each vertex from that vertex's normal. Bilinearly interpolate that color over the polygon. That is called
*Gouraud*shading. - Bilinearly interpolate a surface normal at each pixel from normals that you specified at each vertex. Then normalize the length of each interpolated normal vector. Evaluate the Phong lighting model at each pixel from the interpolated normal. That is called
*Phong*shading.

- Computing surface normals. See page 442ff.
- For a curved surface, the normal vector at a point on the surface is the cross product of two tangent vectors at that point. They must not be parallel to each other.
- If it's a parametric surface, partial derivatives are tangent vectors.
- A
*mesh*is a common way to approximate a complicated surface. - For a mesh of flat (planar) pieces (facets):
- Find the normal to each facet.
- Average the normals of the facets around each vertex to get a normal vector at each vertex.
- Apply Phong (or Gouraud) shading from those vertex normals.

- Texture, chapter 12, pages 467ff.
- fieldAndSky.cpp
- texturedTorus.cpp
- Copy of what I wrote on the tablet.

## Wed 11/9

- This is a regular lecture to replace last Thursday's cancelled lecture.
- We continue to study textures. Important topics:
- Texels vx pixels.
- Minification and magnification.
- GL_NEAREST, GL_LINEAR, etc.
- Aliasing.
- Mipmapping.
- GL_LINEAR_MIPMAP_LINEAR etc.

- fieldAndSkyFiltered.cpp
- compareFilters.cpp
- mipmapLevels.cpp
- buzzwords: LOD (Level Of Detail), multiresolution.
- texturedTorpedo.cpp That uses evaluators and Bezier patches, which we'll see in detail later. However, for now, to understand it, see
- fieldandSkyLit.cpp
- litTexturedCylinder.cpp
- Copy of what I wrote on the tablet.

## Thurs 11/10

Regular lecture: Chapter 13, Special Visual Techniques.

**Week 12**

## Mon 11/14

- Finish chapter 13:
- Stencils: When drawing, update frame buffer only where pixel stencil is set.
- Bump mapping: Perturb normal of smooth surface before computing lighting, to simulate small details.

- Copy of what I wrote on the tablet.

## Thurs 11/17

- Chapter 14, p 527: Raster algorithms
- Cohen-Sutherland line clipping
- Sutherland-Hodgman polygon clipping
- Bresenham line drawing
- Polygon rasterizing: 2 methods.

- Bresenham
- Bresenham's current import is how it made an algorithm more efficient by changing how you look at the problem. It efficiently drew lines and circles mostly using only integer addition - no floating ops and no multiplication or division inside the loop.
- Bresenham presents the fast line and circle drawing algorithms better than the text.

- For more info on testing whether a point is in a polygon, see my note. Also see the comp.graphics.algorithms FAQ, question 2.03.
- The flood fill will fail if the interior is not connected. That happens when two close edges cause adjacent pixels to be set. It will also fail if there is a gap in the perimeter - the color will leak out.
- The scan line fill must handle special cases like a vertex being on a scan line. My solution is to pretend that any vertex on a scan line is really slightly above. This is a simple case of a serious technique called ''Simulation of Simplicity'' invented by Herbert Edelsbrunner.
- Copy of what I wrote on the tablet.

**Week 13**

## Mon 11/21

*Thanksgiving trivia questions:*- What language did Samoset, the first Indian to greet the Pilgrims, in 1621, use?
*Answer:*http://www.holidays.net/thanksgiving/pilgrims.htm - How many European countries had Squanto, the 2nd Indian to greet the

- What language did Samoset, the first Indian to greet the Pilgrims, in 1621, use?
- Chapter 19, page 675: Fixed Functionality Pipelines: We'll skip this (for now), and cover it later or in the spring.
- Chapter 20, page 723: Programmable Pipelines.
- Copy of what I wrote on the tablet.

## Thu 11/25

No lecture. Optional reading material:

- SIGGRAPH 91 and 92 preliminary programs. This is a bowdlerized version, from whence I have removed items that might give offense.
- Raytracing jello brand gelatin

**Week 14**

## Mon 11/28

EMPAC tour led by Eric Ameres

## Thu 12/1

More shader examples. These are from the 4th edition of the
OpenGL Superbible. The local copy of the code is here. The code is arranged in two parallel trees: **src** has the C++ source code, while **projects** has the Makefile, executable, and shader files. Some interesting examples are:

- chapt16/vertexshaders
- chapt17/fragmentshaders
- chapt17/imageproc
- chapt17/lighting
- chapt17/proctex

**Week 15**

## Mon 12/5

- Curves and spline intro
- Reference: Guha, chapter 15.
- My tutorial on Bezier curves.
- Video of Sebastian Thrun's keynote talk at last year's NVidia technical conference. (This is a baseline of a good term project, given that Thrun was hampered by being at Stanford not RPI.) (Local cache). What really causes accidents and congestion on our roadways? How close are we to fully autonomous cars? In his keynote address, Stanford Professor and Google Distinguished Engineer, Dr. Sebastian Thrun, will show how his two autonomous vehicles, Stanley (DARPA Grand Challenge winner), and Junior (2nd Place in the DARPA Urban Challenge) demonstrate how close yet how far away we are to fully autonomous cars. Using computer vision combined with lasers, radars, GPS sensors, gyros, accelerometers, and wheel velocity, the vehicle control systems are able to perceive and plan the routes to safely navigate Stanley and Junior through the courses. However, these closed courses are a far cry from everyday driving. Find out what the team will do next to get one step closer to the holy grail of computer vision, and a huge leap forward toward the concept of fully autonomous vehicles.
- Copy of what I wrote on the tablet.

## Wed 12/7

Fast forward presentations

## Thu 12/8

Fast forward presentations

**Week 16**

## Mon 12/12

- Review
- Office hours this week:
- Tues 1-2pm, Yang Li. JEC 6037. Good time to demo projects.
- Wed, 4-5:30, Qi Wu.

- Copy of what I wrote on the tablet.

## Thurs 12/15

Final exam, DCC330, 3-6 pm.

From the syllabus:

You may bring in any printed material, but no computers. You may not share the material with each other during the exam. No collaboration or communication (except with the staff) is allowed. The final exam will contain material from the whole course, but more from the last half.

**Week 17**

## Mon Dec 19

### Total grade stats

Cutoff QPA Letter Count 0 0 FF 0 48.5 1 DD 1 53.5 1.3 DP 0 58.5 1.7 CM 0 63.5 2 CC 1 68.5 2.3 CP 1 73.5 2.7 BM 2 78.5 3 BB 11 83.5 3.3 BP 16 88.5 3.7 AM 16 93.5 4 AA 7 Class QPA = 3.34

Because the class impressed me so much, I eased the cutoffs somewhat from what was in the syllabus.

### Ending notes

- Comments and sugggestions for improving the course are welcome.
- Even when you're not taking a course from me and even after you graduate, feel free to write or phone with questions are comments about things in general, and to tell me what you're doing.