Game Design Lab 7

Textures: Making Patterns

For this lab, start with the Red Book textures example that we studied in class on Wednesday. Study the code that draws a checkerboard pattern, and modify it to draw colored checks instead. Then, without substantially changing the code, make it draw smaller squares (look at how the checkerboard pattern is determined using bitwise arithmetic). Apply the pattern to a teapot, from glut.
Next, modify the example to rotate the teapot around an axis at 1, 1, 1. This will generate a sort of odd rotation. You'll need to call display as glutIdleFunc as well as glutDisplayFunc before animation will work. 1 degree per frame is about right. You should see your texture pattern on the teapot, rotating in space.
Last week in class, a question was asked regarding making the texture stay put related to the screen while the object rotates under it. This is actually possible. Use glEnable to enable GL_TEXTURE_GEN_S and GL_TEXTURE_GEN_T. S and T are coordinates in the texture image (because X, Y, and Z are already mean other things). You can generate them independently to use a 1-dimensional texture. Try enabling these two before drawing the teapot, and disabling after.
Finally, since glut objects other than the teapot don't have texture coordinates, create a function makeSolidCube that works like glutSolidCube except that it includes texture coordinates. Use the red book square example, and make 6 of them.