Download presentation
Presentation is loading. Please wait.
1
Textures Lecture 11 Wed, Oct 5, 2005
2
Textures A texture is an image that can be “pasted” onto a surface.
The image may be a simple one that was generated within the program, such as a checkerboard, or it may be a photograph (.bmp file).
3
Texture Format There are many internal formats for textures.
GL_RGB – Each texel stored in 3 bytes (red, green, blue) GL_RGBA – Each texel stored in 4 bytes (red, green, blue, alpha) GL_R3_G3_B2 – Each texel stored in 1 byte (3 red bits, 3 green bits, 2 blue bits), etc. We will use the GL_RGB format.
4
Creating Textures The GL_RGB texture image is created as a 3-dimensional array. GLubyte image[rows][cols][3]; We think of it as a 2-dimensional array of vectors. Each vector contains the red, green, and blue values as unsigned integers from 0 to 255.
5
Creating Textures There are also 1-dimensional textures (pasted onto lines) and 3-dimensional textures (pasted onto solids), but we will do only 2-dimensionsal textures.
6
Creating Textures The dimensions of a texture image must be powers of 2, but they need not be the same power of 2. Typical dimensions 256 256 256 512 32 32
7
Example A brick wall texture may be designed as a 8 8 texture.
(192, 0, 0) (208, 208, 208)
8
Tiling Textures Often textures are “tiled” across a surface.
When they are tiled, it is desirable that the images match left-to-right and top-to-bottom. The brick wall texture:
9
Tiling Textures Tiling textures works well if the texture is supposed to have a regular pattern, such as in the case of the brick wall. Other textures look better if there is no discernable pattern, such as leaves.
10
Leaf Texture
11
Another Leaf Texture
12
Window Texture Other textures are not meant to be tiled.
13
Example of Photograph as Texture
Read Run
14
Another Example Read Run
15
Applying Textures When a texture is applied to a polygon, the texels are mapped to the pixels of the rasterized polygon. This usually leads to one of two issues. One texel maps to several pixels. Several texels map to one pixel.
16
Applying Textures Mapping one texel to several pixels is called magnification (because the texel is magnified). Mapping several texels to one pixel is called minification. (The opposite of magnify is minify?)
17
Applying Textures When mapping texels to pixels, we may choose between
Applying the nearest texel. Interpolating among texels. Interpolation uses a weighted average of the 4 nearest texels, weighted by distance. This is called bilinear interpolation.
18
A Checkerboard Texture
Read Run
19
Magnification of Texels (Nearest)
64 Pixels 4 Texels
20
Magnification of Texels (Nearest)
64 Pixels 4 Texels
21
Magnification of Texels (Nearest)
Image copied and pasted from demo program:
22
Magnification of Texels (Interpolated)
64 Pixels 4 Texels
23
Magnification of Texels (Interpolated)
24
Magnification of Texels (Interpolated)
Image copied and pasted from demo program:
25
Close-up of Texture 1:1 (Nearest)
26
Close-up of Texture 2:3 (Nearest)
27
Close-up of Texture 1:1 (Interpolated)
28
Close-up of Texture 2:3 (Interpolated)
29
Minification of Texels (Nearest)
4 Pixels 64 Texels
30
Minification of Texels (Nearest)
“Nearest” texel 4 Pixels 64 Texels
31
Minification of Texels (Nearest)
100% gray 4 Pixels 64 Texels 100% red
32
Minification of Texels (Interpolated)
4 Pixels 64 Texels
33
Minification of Texels (Interpolated)
Nearest 4 texels 4 Pixels 64 Texels
34
Minification of Texels (Interpolated)
100% blue 4 Pixels 64 Texels 75% green, 25% blue
35
The Mapping is not Exact (Nearest)
64 Pixels 36 Texels
36
The Mapping is not Exact (Nearest)
64 Pixels 36 Texels
37
The Mapping is not Exact (Nearest)
64 Pixels 36 Texels
38
The Mapping is not Exact (Interpolated)
64 Pixels 36 Texels
39
The Mapping is not Exact (Interpolated)
42% green, 58% blue 86% green, 14% blue 64 Pixels 36 Texels
40
The Mapping is not Exact (Interpolated)
64 Pixels 36 Texels
41
Applying Textures The situation is often more complicated.
42
Applying Textures The situation is often more complicated.
43
Texture Example Read Run
44
Other Problems When the texel contains a regular pattern, there can be undesirable effects.
45
Other Problems When the texel contains a regular pattern, there can be undesirable effects.
46
Other Problems When the texture contains a regular pattern, there can be undesirable effects.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.