TexturesGL 1.3

glActiveTexture

Chooses which texture unit the next glBindTexture affects.

Signature

void glActiveTexture(GLenum texture);

How it works

To use several textures in one shader, each one goes into a different unit. The pattern is: select unit N → bind texture → tell the sampler uniform to read from N with glUniform1i.

GL_TEXTURE0 is active by default, which is why single-texture code works without calling this.

Parameters

textureGLenum

GL_TEXTURE0 + i, where i is the unit number. GL_TEXTURE0 + 3 == GL_TEXTURE3.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_ENUM
The unit number is ≥ GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS.

Example

example.cpp
1for (int i = 0; i < 3; ++i) {
2    glActiveTexture(GL_TEXTURE0 + i);
3    glBindTexture(GL_TEXTURE_2D, textures[i]);
4}
Official Khronos documentation