CS 450/550 -- Fall Quarter 2022

Project #3

100 Points

Due: October 19

Texture Mapping


This page was last updated: September 4, 2022


Introduction

The goal of this project is to map a texture (your choice) to an object (your choice) and then distort it in some way. What you do here is up to you, but make it more than trivial. But, whatever you do, make it so that you could not do the same thing with a texture transformation. That is, no rigid body rotates, scales, or translates. That is, the distortion must be different all over the object. You can't just slide the texture around or up/down the object.

Hint: Try changing a vertex's s coordinate as a function of its t coordinate, or vice versa.

Requirements:

  1. Read in a texture image. The choice of image is up to you. Use the BmpToTexture( ) function to read it in. Some older graphics cards require the dimensions of this image be powers of two. So, if the texture on your object looks weird, try making the object dimensions come out to powers of two.

  2. Create a 3D object that has texture coordinates (s,t) at the vertices, specified by glTexCoord2f( ) calls before each call to glVertex3f( ). Since you will be modifying the creation of the (s,t) texture coordinates, this needs to be an object that you have source-code control over. A cube would work, but is boring. Whatever you did for Project #1 might work. The OsuSphere works very well and would be a good place to start even if you are planning to eventually use something else.

  3. Under control of your GLUT Idle Function, animate the texture distortion. (See below for some advice on doing this.)

  4. Under control of a right-mouse-button menu option, allow the object to be displayed:
    1. With no texture -- just an unlit blob-ish color.
    2. With your texture image GL_REPLACE'ed on it.
    3. With some distortion of the texture-image GL_REPLACE'ed on it.

  5. The distortion should be done by re-drawing the object with a distorted texture coordinate pattern.

Turn-in:

Use the Teach system to turn in your:

  1. .cpp file
  2. A one-page PDF with a title, your name, your email address, a nice screen shot from your program, and the link to the video demonstrating that your project does what the requirements ask for. Narrate your video so that you can tell us what it is doing.
  3. You can use whatever video-capture tool you want. Kaltura and Zoom both work well.

Files You Might Want

Click here to get the BmpToTexture( ) function. (It is already in your sample code.)

Click here to get the worldtex.bmp file.

Click here to get the OsuSphere( ) function.

Timing Your Scene Animation

We have talked about the difference between running your animation just as fast as the system you are on can get around to calling the Idle Function versus deliberately timing the animation. Here is a good way to do that:

Set a constant called something like MS_PER_CYCLE that specifies the number of milliseconds per animation cycle. Then, in your Idle Function, query the number of milliseconds since your program started and turn that into a floating point number between 0. and 1. that indicates how far through the animation cycle you are. So, in Animate, you might say:


int ms = glutGet( GLUT_ELAPSED_TIME );
ms %= MS_PER_CYCLE;
Time = (float)ms / (float)MS_PER_CYCLE;		// [0.,1.)
and then in Display( ), you might use that 0.-1. number something like this:
glRotatef( 360.*Time, 0., 1., 0. );

Distorting a Texture

You can't really dynamically distort the texture image, but you can distort the texture coordinates. For example, if you are using the OsuSphere( ) function, you might insert something here:
if( ! Distort )
{
	p->s = ( lng + M_PI    ) / ( 2.*M_PI );		// the correct code
	p->t = ( lat + M_PI/2. ) / M_PI;		// the correct code
}
else
{
	. . .						// the distortion code
	. . .						// the distortion code
}
So that if the Distort global variable is true, you do something "wrong" to compute the s and t coordinates.

Something to Notice

If you do use the sphere with the Earth texture, so that it looks like a globe, you will find that orthographic looks nicer than perspective. You can see more of the sphere this way. Try it.

Only Do It This Way for This Project!

Normally we don't want to distort texture coordinates, we just want to display the object correctly. So, except for in this project, you will likely place the entire object in a Display List!

Grading:

Item Points
Correctly draw the blob-ish object 20
Correctly draw the normal-texture object 30
Correctly draw the distorted-texture object 50
Potential Total 100