Course list http://www.c-jump.com/bcc/

Textures in OpenGL


  1. Introduction
  2. Texture mapping
  3. How is texture applied to a surface?
  4. Texture coordinates
  5. Texture coordinates, cont.
  6. How is texture image loaded?
  7. Texture example (client side)
  8. What is texture object?
  9. What is texture unit?
  10. Internal texture image format
  11. The fragment shader code
  12. Texture sampling in GLSL
  13. The fragment shader code, cont.
  14. Texture binding, revisited
  15. Texture preferences
  16. Texture wrap parameters
  17. Texture wrap parameters, cont.
  18. Texture wrap parameters, cont.
  19. Minification and magnification
  20. Minification and magnification, cont
  21. Minification vs. Mipmapping
  22. Mipmap example
  23. Loading bitmap image files
  24. Texturing summary

1. Introduction



2. Texture mapping



3. How is texture applied to a surface?



4. Texture coordinates



5. Texture coordinates, cont.



6. How is texture image loaded?


  • Texture image originates as an array of texels in CPU memory.

    A texel is a texture element: i.e. the color to be applied to an interpolated fragment

  • The C++ client code

    • fills the array of data from an image, or

    • generates the texels programmatically

    texture mapping

7. Texture example (client side)



8. What is texture object?



9. What is texture unit?



10. Internal texture image format



11. The fragment shader code



12. Texture sampling in GLSL


  • Vertex shader

    
    // ...
    // UV coordinates:
    in vec2 s_vTexCoord;
    out vec2 texCoord;
    // ...
    void main () {
        // ...
        // Pass UV coordinates to
        // the fragment shader:
        texCoord = s_vTexCoord;
        // ...
    
    
  • Fragment shader

    
    // sampler2D provides access
    // to the texture image
    in vec2 texCoord;                
    uniform sampler2D texture;
    out vec4 fColor;
    void main () {
        // ...
        // Diffuse light is based on
        // normal N, light vector L,
        // and the texel color returned
        // by texture2D():
        float diffuse_intensity =
            max( dot( N, L ), 0.0 );
        vec4 diffuse_final =
            diffuse_intensity
            *
            texture2D( texture, texCoord )
            ;
        // ...
    
    

13. The fragment shader code, cont.



14. Texture binding, revisited



15. Texture preferences



16. Texture wrap parameters



17. Texture wrap parameters, cont.



18. Texture wrap parameters, cont.



19. Minification and magnification



20. Minification and magnification, cont


  • GL_NEAREST returns the nearest texel to the sample location
    texture parameter values

  • GL_LINEAR enables linear texel filtering
    texture parameter values


21. Minification vs. Mipmapping



22. Mipmap example



23. Loading bitmap image files



24. Texturing summary