0% found this document useful (0 votes)
66 views28 pages

And Visualization: 04 - Texture Mapping

This document discusses texture mapping concepts in computer graphics, including: - Texture coordinates (UV mapping) and how they associate texture pixels with geometry - Texture filtering methods for magnification and minification such as nearest neighbor and linear filtering - Mipmapping techniques for reducing aliasing by providing multiple texture resolutions - Texture wrapping modes like repeat, mirror, and clamp for handling texture coordinates outside the 0-1 range - Implementing texture mapping in OpenGL through functions like glTexImage2D, glTexParameteri, and glGenerateMipMap The goal is to explain these techniques and have the reader practice drawing textured cubes and planes in OpenGL.

Uploaded by

Achmad Taufiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views28 pages

And Visualization: 04 - Texture Mapping

This document discusses texture mapping concepts in computer graphics, including: - Texture coordinates (UV mapping) and how they associate texture pixels with geometry - Texture filtering methods for magnification and minification such as nearest neighbor and linear filtering - Mipmapping techniques for reducing aliasing by providing multiple texture resolutions - Texture wrapping modes like repeat, mirror, and clamp for handling texture coordinates outside the 0-1 range - Implementing texture mapping in OpenGL through functions like glTexImage2D, glTexParameteri, and glGenerateMipMap The goal is to explain these techniques and have the reader practice drawing textured cubes and planes in OpenGL.

Uploaded by

Achmad Taufiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

AND VISUALIZATION

04 | Texture Mapping
COMPUTER GRAPHICS AND VISUALIZATION
Agenda
 Introduction to Textures.
 Texture Uvs.
 UV Mapping.
 Magnification & Minification.
 Mipmapping.
 Anisotropic.
COMPUTER GRAPHICS AND VISUALIZATION
Objectives
 Explain Texture Mapping Concepts.
 Implement Texture Mapping in OpenGL.
COMPUTER GRAPHICS AND VISUALIZATION
How Texturing Works
COMPUTER GRAPHICS AND VISUALIZATION
Texture UVs
COMPUTER GRAPHICS AND VISUALIZATION
COMPUTER GRAPHICS AND VISUALIZATION
Texel Coordinates

What texel, column and


row, is located at the U,V
coordinate ( 0.72, 0.40 )?
column = 0.72 * 16 =
11.52 = 11
row = 0.40 * 16 = 6.4 = 6
COMPUTER GRAPHICS AND VISUALIZATION
Generate Texture in OpenGL
 Load texture from image (PNG, JPEG, etc).
 glGenTextures(textureIDBuffer);
 glBindTexture(GL_TEXTURE_2D, texID); // Bind Target
 glTexImage2D(GL_TEXTURE_2D, // Texture Type
0, // Level
GL_RGBA, // Internal Format
m_texture.getWidth(), texture.getHeight(),
0, // Border
GL_RGBA, // External Format
GL_UNSIGNED_BYTE, // Pixel Data type
texture.getImageData() // Pixel Data);
COMPUTER GRAPHICS AND VISUALIZATION
Texture Mapping in OpenGL
Mapping between geometry coordinates and
UV coordinates in OpenGL :
glTexCoord2d(u, v);
glVertex3f(x, y, z);
Don’t use this, because we’re using VBO!
Before mapping don’t forget to bind target
texture.
Texture Distortion

COMPUTER GRAPHICS AND VISUALIZATION


(0,1) (1,1) (0,1) (3,1) (0,3) (1,3) (0,3) (3,3)

(0,0) (1,0) (0,0) (3,0) (0,0) (1,0) (0,0) (3,0)

(0,1) (0.5,1) (0,0.5) (1,0.5) (0,0.5) (0.5,0.5)

(0,0) (0.5,0) (0,0) (1,0) (0,0) (0.5,0)


COMPUTER GRAPHICS AND VISUALIZATION
Wrap Modes
COMPUTER GRAPHICS AND VISUALIZATION
Wrap Modes in OpenGL
Wrap Mode :
 GL_REPEAT: The integer part of the coordinate will be ignored and a repeating
pattern is formed.
 GL_MIRRORED_REPEAT: The texture will also be repeated, but it will be mirrored
when the integer part of the coordinate is odd.
 GL_CLAMP_TO_EDGE: The coordinate will simply be clamped between 0 and 1.
 GL_CLAMP_TO_BORDER: The coordinates that fall outside the range will be given a
specified border color.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode);
COMPUTER GRAPHICS AND VISUALIZATION
Magnification and Minification
COMPUTER GRAPHICS AND VISUALIZATION
Texture Magnification Filter
COMPUTER GRAPHICS AND VISUALIZATION
Ratio : texels / pixels
COMPUTER GRAPHICS AND VISUALIZATION
Nearest Neighbors Magnification Filter

Texture Size : 2x2 Texel Texture Size : 64x64 Texel


COMPUTER GRAPHICS AND VISUALIZATION
Linear Magnification Filter

Texture Size : 2x2 Texel Texture Size : 64x64 Texel


COMPUTER GRAPHICS AND VISUALIZATION
Smooth to Sharp

64x64 Texel 128x128 Texel


COMPUTER GRAPHICS AND VISUALIZATION
x
x
x
x
COMPUTER GRAPHICS AND VISUALIZATION
Magnification and Minification Filter in OpenGL
Filter :
 GL_NEAREST: Returns the pixel that is closest to the coordinates.
 GL_LINEAR: Returns the weighted average of the 4 pixels surrounding the
given coordinates.
 GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST,
GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR: Sample
from mipmaps instead.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
COMPUTER GRAPHICS AND VISUALIZATION
Mipmapping
COMPUTER GRAPHICS AND VISUALIZATION
Mipmapping Algorithm
COMPUTER GRAPHICS AND VISUALIZATION
Generate Mipmapping in OpenGL
 gluBuild2DMipmaps(
target, // Texture ID
GL_RGB, // Internal Texel Format,
texture.getWidth(), texture.getHeight(),
GL_RGB, // External format from image,
GL_UNSIGNED_BYTE,
texture.getImageData() // Imagedata
);
 glGenerateMipMap()
COMPUTER GRAPHICS AND VISUALIZATION
COMPUTER GRAPHICS AND VISUALIZATION
Mipmaping Problem
COMPUTER GRAPHICS AND VISUALIZATION
COMPUTER GRAPHICS AND VISUALIZATION
Practice: Draw textured cube and plane
COMPUTER GRAPHICS AND VISUALIZATION
References
 Interactive 3D Graphics, Autodesk, Eric Haines.
 Beginning OpenGL Game Programming, Course
Technology PTR, Luke Benstead, Dave Astle, Kevin
Hawkins.

You might also like