1 of 13

Texture

2 of 13

Texture Mapping

  • Map the texture onto 3D mesh.

3 of 13

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 13

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 13

Texture Wrapping

  • When uv cordinate not in 0~1

6 of 13

Texture Filtering

7 of 13

Texture Filtering

Texture

Polygon

Magnification

Minification

Polygon

Texture

8 of 13

Texture Filtering

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

9 of 13

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

10 of 13

Mipmaps

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

11 of 13

Generating & Applying Textures

12 of 13

Generating Textures

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

Fragment shader

13 of 13

Reference