This project is an alternative to the Geometry Shader Project #7 for those who do not have access to a system that can handle Geometry Shaders. All others must do the Geometry Shader Project #7.
If you think you did this project in CS 450/550, note that this one is different!
This page was last updated: February 26, 2023
The goal of this project is to map a texture (your choice) to an object (your choice) and then distort it in some way. Use shaders to change a vertex's s and t coordinates. 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 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.
A Possibility: Use shaders to change a vertex's s coordinates as a function of its t coordinate, or vice versa.
Use the Teach system to turn in your:
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.
Here is a good way to animate:
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:
#define MS_PER_CYCLE 10000 . . . int ms = glutGet( GLUT_ELAPSED_TIME ); ms %= MS_PER_CYCLE; Time = (float)ms / (float)MS_PER_CYCLE; // [0.,1.)
In the global variables:
unsigned char * Texture; // the texels
unsigned int WorldTex; // the texture object
unsigned int MyObjectList; // the display list object
At the end of InitGraphics( ), read the texture and create a texture object from it:
int width, height;
Texture = BmpToTexture( (char *)"worldtex.bmp", &width, &height );
if( Texture == NULL )
fprintf( stderr, "Cannot open texture '%s'\n", "worldtex.bmp" );
else
fprintf( stderr, "Width = %d ; Height = %d\n", width, height );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glGenTextures( 1, &WorldTex );
glBindTexture( GL_TEXTURE_2D, WorldTex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture );
Then, after that in InitGraphics( ):
glGenLists( 1, &MyObjectList );
glNewList( MyObject, GL_COMPILE );
OsuSphere( 2.f, 30, 30 ); // or something else, such as reading an OBJ file
glEndList( );
Pattern->Use( ); glActiveTexture( GL_TEXTURE6 ); // use texture unit 6 glBindTexture( GL_TEXTURE_2D, WorldTex ); Pattern->SetUniformVariable( "uTime", Time ); Pattern->SetUniformVariable( "uTexUnit", 6 ); glCallList( MyObjectList ); Pattern->Use( 0 ); // or Pattern->UnUse( )
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.
Item | Points |
Correctly draw the normal-texture object | 40 |
Correctly draw the distorted-texture object | 30 |
Correctly animate the distorted-texture object | 30 |
Potential Total | 100 |