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
There are a number of interesting issues that arise with texturing
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.
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.
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.
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.
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.
Consider the following:
Written by Scott D. Anderson
scott.anderson@acm.org

This work is licensed under a Creative Commons
License.