1 of 18

Texture

2 of 18

Texture Mapping

  • Map the texture onto 3D mesh.

3 of 18

Texture Coordinates

http://www.c-jump.com/bcc/common/Talk3/OpenGL/Wk07_texture/Wk07_texture.html

  • Range from 0 to 1 in the x and y axis
  • To retrieve the texture color (sampling)

4 of 18

Texture Coordinates

  • Specify texture coordinate points for the 3d model
  • Pass the texture coordinates to the vertex shader & fragment shader
  • Interpolate all the texture coordinates for each fragment

5 of 18

Texture Wrapping

6 of 18

Texture Filtering

  • Determine which texture pixel (also known as a texel) to map the texture coordinate to.

7 of 18

Texture Filtering

8 of 18

Texture Filtering

Texture

Polygon

Magnification

Minification

Polygon

Texture

9 of 18

Texture Filtering

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

10 of 18

Mipmaps

  • Small objects with the high solution texture
  • Each subsequent texture is twice as small compared to the previous one

=> visible artifacts & waste of memory

  • Less cache memory

11 of 18

Mipmaps

  • GL_NEAREST_MIPMAP_NEAREST
  • GL_LINEAR_MIPMAP_NEAREST
  • GL_NEAREST_MIPMAP_LINEAR
  • GL_LINEAR_MIPMAP_LINEAR

12 of 18

Mipmaps

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

13 of 18

Generating & Applying Textures

14 of 18

Generating Textures

  • Read the image from file input stream.
  • Generate the texture object.
  • Bind and setup the texture object.

15 of 18

Applying Textures

16 of 18

Applying Textures

Vertex Shader

Fragment Shader

17 of 18

Applying Textures

18 of 18

Reference