Plan

Image Files and Formats

To see the magic bytes at the beginning of a file, use a Unix program called od (for octal dump).

To do scriptable conversion among file formats, use the commands in the Netpbm toolkit. Let's do an example that re-sizes a file to powers of two dimensions:

jpegtopnm cookie_monster.jpg | pamscale -xsize=512 -ysize=512 > cookie_monster.ppm
od -c cookie_monster.ppm | head

Texture Issues

There are a number of interesting issues that arise with texturing

Binding

We use texture-binding for speed. The graphics card gets several textures loaded at initialization time, and each is associated with an id. The id is just an arbitrary number that the graphic card assigns. Then at rendering time, we specify which texture number we want, and it's ready to go in a moment, without sending it down the pipeline again.

Stretching

For your textures to look good, you want a good ratio between texels and pixels. If your quads end up big, due to the camera zooming in or foreshortening (as in this demo), the texture ends up looking stretched out, which can look funny. Type 'r' to reveal the underlying quads, type 'c' to show color instead, and type 0,1,2 to get three different textures.

Grass.py

Lighting

You usually want your texture to interact with light. Here's an example where we make a gray flag and texture-map the USflag on it. Since we haven't studied Bezier surfaces, we won't dig into that part of the code. Just focus on the use of GL_MODULATE.

LitUSFlag.cc

Non-rectangular Shapes

Texture-mapping onto non-rectangular shapes can be hard. The easiest is a cylinder, which is really a rectangle bent around in 3D. Texture-mapping onto a globe is the opposite of the cartographer's problem. Texture-mapping onto a triangle poses some troubles that are best fixed with Bezier surfaces.

Lab Exercise

Copy the file buffy-cube-lab.py. Compile and run it. Take a minute to read the code and understand it.

Then, choose another BtVS character (or any picture at all) and texture-map that picture on the other three faces. Make the upper-left corners coincide!

Switch to using lighting and use modulate for the textures. The result should look a bit like TextureBinding.py

Try replacing one of the pictures with one from the web.

Additional Demos

Consider the following:

Written by Scott D. Anderson
scott.anderson@acm.org
Creative Commons License
This work is licensed under a Creative Commons License.

Valid HTML 4.01!