Texture Mapping Introduction What is Texture Mapping Types














- Slides: 14

Texture Mapping

Introduction • What is Texture Mapping? • Types of Texture Mapping – 1 D, 2 D and 3 D • SDL and Open. GL

Getting Your Feet Wet • Five Steps in Getting Texture Mapping to Work – 1. Load the Bitmap – 2. Generate the Texture Handle – 3. Bind and Configure – 4. Build Texture in Open. GL – 5. Bind and Use

A Little More Detail • 1. Load Bitmap • 2. Generate a Texture Handle – gl. Gen. Textures(1, &temptex); • 3. Bind and Configure – – – gl. Bind. Texture (GL_TEXTURE_2 D, n. New. Texture. ID); gl. Tex. Parameteri (GL_TEXTURE_2 D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl. Tex. Parameteri (GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl. Tex. Parameteri (GL_TEXTURE_2 D, GL_TEXTURE_WRAP_S, GL_REPEAT); gl. Tex. Parameteri (GL_TEXTURE_2 D, GL_TEXTURE_WRAP_T, GL_REPEAT); • 4. Build the Texture in Open. GL – glu. Build 2 DMipmaps (GL_TEXTURE_2 D, n. BPP, n. Width, n. Height, – (n. BPP == 3 ? GL_RGB : GL_RGBA), GL_UNSIGNED_BYTE, – p. Data);

In Depth Discussion • The Bitmap File Format – File Header • Size and Type of File – Info Header • Image dimensions • Bits per Pixel (BPP) – Image Data(unsigned char) • What can be used as a Texture?

In Depth Discussion • Texture Handle Generation – gl. Gen. Textures(1, &temptex); – GL_TEXTURE_1 D and GL_TEXTURE_3 D • Texture Binding – gl. Bind. Texture (GL_TEXTURE_2 D, Texture. ID); • Environment Settings – gl. Tex. Envi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); – GL_DECAL and GL_BLEND

In Depth Discussion • Texture Wrapping Parameters – gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_WRAP_S, GL_REPEAT); – gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_WRAP_T, GL_REPEAT); – Also GL_CLAMP

In Depth Discussion • Texture Resizing Filters – gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) – GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, and GL_LINEAR_MIPMAP_LINEAR – gl. Tex. Parameteri(GL_TEXTURE_2 D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) – GL_LINEAR

In Depth Discussion • What are Mipmaps? • Building the Texture – glu. Build 2 DMipmaps(GL_TEXTURE_2 D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, data) • Using the Texture – gl. Tex. Coord 2 f(0. 0, 1. 0); gl. Vertex 3 i(-1, 1, 1)

Texture and Lighting • Four Steps for Lighting – – Calculate Normals Position Light Choose Shading Model Set Material • Setting Materials – gl. Materialfv(GL_FRONT, GL_AMBIENT, mat. Ambient) – gl. Materialfv(GL_FRONT, GL_DIFFUSE, mat. Diffuse)

Texture Transparency • The Blending Function – gl. Enable(GL_BLEND); – gl. Blend. Func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); – gl. Color 4 f(1. 0 f, 0. 5) • Depth Testing Issues

Playing with Texture Coordinates • Easy as Pie • Take your original Texture coordinates and move them around • Use Texture Coordinates to only show part of the image • Textured Fonts

Multi-Pass Multi-Texturing • What is Multi-Texturing • Why not Single Pass Multi-Texturing • How to do Multi-Pass Multi-Texturing – 1. Draw your object with base texture – 2. Draw your object again with blended texture – 3. Repeat step 2 till satisfied

Advanced Topics • Other uses of Texture Mapping – Imposters – Lightmapping – Shadowmapping – Environment Mapping – Projective Texturing • Procedural Texture Generation