Cg Textures Lab2

3
Lab: Texture Mapping - Auto Generation of Coordinates, Filtering, Wrapping This lab explores some advanced features of texture mapping in OpenGL. 1 Automatic Generation of Texture Coordinates Download the file named autotexcoords.c into your directory. This is essentially the code used in the Programmers’ Guide to demonstrate the use of glTexGen. The code has been modified to include rotation about the Z and Y axes. Program control is via the keyboard. e sets EYE LINEAR mode o sets OBJECT LINEAR mode s sets the plane to x + y + z = 0 (slanted) x sets the plane to x =0 z rotates about the Z axis y rotates about the Y axis q exits the program Execute the program, observing all combinations of mapping mode and plane. Q1: Describe the results of EYE LINEAR and x + y + z =0. Q2: Describe the results of EYE LINEAR and x =0. Q3: Describe the results of OBJECT LINEAR and x + y + z =0. Q4: Describe the results of OBJECT LINEAR and x =0. Now see what happens with a 2D texture. Uncomment the code to buildTexture and the call to it in init. You need to enable 2D texturing and automatic generation of the T texture coordinate, and change all other 1D references to 2D. What we’re concerned with is the modes for generating S and T coordinates and their interaction. Duplicate the 2 calls to glTexGen, using one pair for S, the other for T . Rather than use the keyboard to change the currentCoeff and currentGenM ode variables, simply hardcode them as described below. (Note: You can add options to the keyboard function. If you do, just make sure that you can change S and T values independently.) Try the following combinations and observe the results. case S T a) EYE LINEAR, EYE PLANE, slanted EYE LINEAR, EYE PLANE, slanted b) OBJECT LINEAR, OBJECT PLANE, slanted OBJECT LINEAR, OBJECT PLANE, slanted c) OBJECT LINEAR, OBJECT PLANE, slanted EYE LINEAR, EYE PLANE, slanted d) OBJECT LINEAR, OBJECT PLANE, slanted EYE LINEAR, EYE PLANE, xequalzero Q5: Describe the results for case a). Q6: Describe the results for case b). Q7: Describe the results for case c). Q8: Describe the results for case d). Variations: Play with the p i values to see how they affect the results. 1

description

VALUEABLE BOOKING

Transcript of Cg Textures Lab2

Page 1: Cg Textures Lab2

Lab: Texture Mapping - Auto Generation of Coordinates, Filtering, Wrapping

This lab explores some advanced features of texture mapping in OpenGL.

1 Automatic Generation of Texture Coordinates

Download the file named autotexcoords.c into your directory. This is essentially the code used in the Programmers’ Guide todemonstrate the use of glTexGen. The code has been modified to include rotation about the Z and Y axes. Program controlis via the keyboard.

• e sets EYE LINEAR mode

• o sets OBJECT LINEAR mode

• s sets the plane to x + y + z = 0 (slanted)

• x sets the plane to x = 0

• z rotates about the Z axis

• y rotates about the Y axis

• q exits the program

Execute the program, observing all combinations of mapping mode and plane.

Q1: Describe the results of EYE LINEAR and x + y + z = 0.Q2: Describe the results of EYE LINEAR and x = 0.Q3: Describe the results of OBJECT LINEAR and x + y + z = 0.Q4: Describe the results of OBJECT LINEAR and x = 0.

Now see what happens with a 2D texture. Uncomment the code to buildTexture and the call to it in init. You need to enable2D texturing and automatic generation of the T texture coordinate, and change all other 1D references to 2D. What we’reconcerned with is the modes for generating S and T coordinates and their interaction. Duplicate the 2 calls to glTexGen,using one pair for S, the other for T . Rather than use the keyboard to change the currentCoeff and currentGenModevariables, simply hardcode them as described below. (Note: You can add options to the keyboard function. If you do, justmake sure that you can change S and T values independently.)

Try the following combinations and observe the results.

case S Ta) EYE LINEAR, EYE PLANE, slanted EYE LINEAR, EYE PLANE, slantedb) OBJECT LINEAR, OBJECT PLANE, slanted OBJECT LINEAR, OBJECT PLANE, slantedc) OBJECT LINEAR, OBJECT PLANE, slanted EYE LINEAR, EYE PLANE, slantedd) OBJECT LINEAR, OBJECT PLANE, slanted EYE LINEAR, EYE PLANE, xequalzero

Q5: Describe the results for case a).Q6: Describe the results for case b).Q7: Describe the results for case c).Q8: Describe the results for case d).

Variations: Play with the pi values to see how they affect the results.

1

Page 2: Cg Textures Lab2

2 Loading Bitmaps From a File

Download the files named bmp-loader.c, bitmap.c, and bitmap.h into your directory. The two bitmap files convert a bitmapinto an array usable by OpenGL. bmp-loader simply applies the texture to a surface. MS Paint (as well as many otherprograms) can be used to convert gif and jpeg files to bmp format for use with bitmap, so it’s general enough for mostpurposes.

bmp-loader maps a 64× 64 pixel bitmap (grass64) onto a surface. Before you try to use it, you need to download the bitmapfile, and make sure that the path is correct in the code.

You can download other images and edit them - remember that OpenGL insists on texture dimensions that are equal to 2n

or 2n + 2 (when including a one-pixel border).

3 Magnification and Minification Filters

This part examines the effect of magnification and minification of textures and how filtering affects the results. Use filetex-lab2-zoom, which is simply bmp-loader with zooming incorporated. The j and k keys zoom in and out from the surfacebeing displayed. Use the grass64 bitmap for this.

First, we’ll use GL TEXTURE MAG FILTER with glTexParameter. It has 2 values: GL NEAREST and GL LINEAR.What you’ll want to do is to set one of these values, then look at the texture-mapped surface under increasing magnifications.It’s most instructive to do this interactively by zooming the camera in and out. You want to compare the qualities of theimages using the 2 parameter values. You could add an option to the keyboard function to toggle back and forth betweenthe two modes, or simply hardcode and recompile.

Q9: Compare the results of linear mode to those of nearest mode.

Repeat the above using parameter GL TEXTURE MIN FILTER with GL NEAREST and GL LINEAR.

Q10: Compare the results of linear mode to those of nearest mode.

3.1 Texture Wrapping

Now we’ll look at variations in applying the texture across a surface. Use tiling.c for this. It’s basically the same programas bmp-loader.c. For this part, the surface is 2 times wider and 3 times taller than it was. The texture coordinates are setto extend from 0.0 to 3.0 horizontally, and 0.0 to 2.0 vertically.

We’ll start off using the same sets of values for GL TEXTURE WRAP S and GL TEXTURE WRAP T. Use the indicatedvalues for each of these parameters to glTexParameter. You might want to use grass64 as the texture initially (it’s thetexture referred to throughout), and then repeat using a texture that’s less organic (e.g., pattern1-64).

1. Use value GL REPEAT (default).

Q11: Describe your results.

2. Use value GL MIRRORED REPEAT.

Q12: Describe your results.

3. Use GL CLAMP.

Q13: Describe your results.

2

Page 3: Cg Textures Lab2

4. Repeat using GL CLAMP, but load grass66.bmp. This is the same bitmap as grass64 except that it has a one pixelborder around it.

Q14: Describe your results.

5. Keeping the border, use GL CLAMP TO BORDER.

Q15: Describe your results.

6. Keeping the border, use GL CLAMP TO EDGE.

Q16: Describe your results.

7. Repeat the above steps 4, 5, and 6 (dealing with borders), but use GL NEAREST instead of GL LINEAR.

Q17: Describe your results.

8. Repeat the above steps (4, 5, 6, 7) going back to the grass64 texture again. This time, specify a border color of yourchoice (TEXTURE BORDER COLOR) and observe the effect.

Q18: Describe your results.

Now use different combinations of values for the S and T directions.

3