<<< The fragment shader code, cont. | Index | Texture preferences >>> |
OpenGL has an array of texture image units, also known as image units or texture units
One unit represents a single texture
A sampler uniform in the shader has to be connected to a particular image unit
Due to some legacy issues, to associate a texture object with a sampler in the shader requires two steps:
texture_ID = glGetUniformLocation( shader_program_ID, "texture" ); const int TEXTURE_UNIT_ZERO = 0; // First, activate texture unit (relative to GL_TEXTURE0) glActiveTexture( GL_TEXTURE0 + TEXTURE_UNIT_ZERO ); // Second, tell "texture" sampler to use the 0th texture unit: glUniform1i( texture_ID, TEXTURE_UNIT_ZERO );
Also, note that sampler uniforms are considered 1-dimesional (scalar) integer values on the C++ client side, so we call glUniform1i()
<<< The fragment shader code, cont. | Index | Texture preferences >>> |