### CSC 240: Computer Graphics

Homework 7: Texture Mapping in OpenGL

Due: Thursday, Nov. 19, 11:59pm on Moodle

The goal of this homework is to practice texture mapping in OpenGL.

Part 1: Texture mapping flat surfaces

For this part, finish Lab 13, with the goal of creating a "room" with texture on each surface.

Requirements:

1. Select a viewpoint so the room looks 3D (similar to the last picture in Lab 13, so you can see a corner of the room).

2. There should be a floor, a ceiling/roof, and at least 2 walls visible. Each of these (floor, ceiling, wall) should have a different texture.

3. For at least one texture, the pattern should repeat to tile the surface. For this texture, it should "line up" on the top/bottom and left/right so that it looks uninterrupted. The wallpaper texture is a good example of something that could be modified to match up.

4. At least one texture should be yours that you've downloaded or created.

5. Your room should also have a table resting on the floor to provide some perspective, but this does not need to be texture mapped.

Submit your code on Moodle, along with a screenshot of the image I should get if I run the code (no need for animation, one viewpoint is good).

Note: to use your own texture, you'll need to download Pillow (described in Lab 13). If this is not working, send me your texture and I can make a PPM-like text file to use instead.

Part 2: Texture mapping spheres

For this part, the goal is to texture map a sphere with a map of the world, to make it look like a globe. Here is the texture:

You can start from this code:

Right now this code should produce a blank sphere.

Requirements:

1. Implement the method
`def uv_coords(dx,dy,dz)`
which should take in a point on the sphere and return the UV coordinates corresponding to the correct point on the texture. So U and V should both be between 0 and 1.

2. Once you've implemented this method, apply the texture to the sphere within the method
` myGlutSolidSphere `
(This code for the sphere is based on the C source code for glutSolidSphere.)

3. Implement the "special" function so that if the left or right arrows are pressed, the globe rotates around the y-axis (similar idea to the robot arm movement). If the up or down keys are pressed, the globe should rotate around the x-axis.

4. Submit your code on Moodle, along with a screen shot of what I should get if I run your code.

Notes:

• If the texture is taking too long to load or you're running into seg fault or overflow errors, let me know and I can make the image smaller.

• If you'd like to use a more realistic map image that's fine too!

COLLABORATION:

For this assignment, you are welcome to work together, but everyone should turn in their own code that they have written and understood. Please cite anyone you worked with at the top of your assignment.