Lab 6

Lab 6: Texture Experiments

Due: Thursday, November 4th, 2010 (by the end of lab session)

In this lab assignment, you will modify some base code to allow you to quickly change OpenGL texture parameters and see how those parameters affect your model in realtime. Your base code will load a PPM specified on the command line and display that texture on a simple XY plane. The texture coordinates on the plane range from (-2,-2) to (3,3) to help visualize what happens to texture coordinates beyond (0,1).

For the assignment, you will implement keyboard shortcuts to allow the user to quickly change texture parameters on the fly and visualize the results. Note that you do not need to reload the texture with glTexImage2D after you make texture parameter changes for them to take effect, but you do need to make sure that textures are enabled and that your current texture handle is bound with glBindTexture() before you attempt to change parameters.

There is also a writeup associated with the lab, located in the base code as writeup.txt. Fill out the writeup and leave it in the same directory as your submission -- you will need to submit both the writeup and your modified source code. As usual, you are expected to place your name in your source files and comment your changes appropriately.

Base Code

Download this base code for your assignment:

Lab 6 base code.

The base code includes a simple main.cpp, Makefile, and two textures: monogram_button.ppm and monogram_button_lowres.ppm. The base code loads a texture from the command line, but you can use monogram_button.ppm for most of the assignment. monogram_button_lowres.ppm is specifically to exaggerate the effects of filtering.

Part 1 - Texture Wrapping

Texture wrapping determines how OpenGL handles texture coordinates outside the range of [0,1]. Allow the user to toggle between the following different modes of texture wrapping: GL_CLAMP, GL_REPEAT, and GL_MIRRORED_REPEAT. For this assignment, we will ignore GL_CLAMP_TO_BORDER and GL_CLAMP_TO_EDGE, though it is encouraged you read up on these and experiment with them if you have interest; in most applications, GL_CLAMP_TO_EDGE is preferable over GL_CLAMP.

The current texture wrapping mode is set for each texture dimension, s and t, separately with a call to glTexParameterf, e.g.:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

Once you can toggle between the three modes in your program, answer the questions from the texture wrapping section in your writeup.

Part 2 - Texture Modulation

Texture modulation determines how the colors of the texture blend with the object and how they interact with lighting parameters in OpenGL. Implement a keyboard shortcut that allows the user to toggle between texture modulation (GL_MODULATE) and texture replacement (GL_REPLACE). This is accomplished with a call to glTexEnvf(), e.g.:

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Once you have implmented this functionality, finish the texture modulation section of the writeup. Feel free to check the man page for glTexEnv and experiment with other modulation modes.

Part 3 - Minification and Magnification Filters

For this section, use the monogram_button_lowres.ppm input file.

Magnification and minification filters will determine the appearance of the texture when one pixel corresponds to multiple texels or vice versa. It is set with a call to glTexParameterf(), and the minification and magnification filters must be set separately, e.g.:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Allow the user to toggle between GL_NEAREST and GL_LINEAR, and then complete the corresponding section of the writeup. The effect of the filters will be much more noticeable if you use the low resolution texture and zoom in.

Submission

Submit your lab 6 in your dropbox in the following location:

/afs/nd.edu/coursefa.10/cse/cse40166.01/dropbox/<afsid>/lab6

Your submission should include your code, Makefile, and lab writeup.