TexturesGL 1.1

glBindTexture

Binds a texture to a target of the ACTIVE texture unit.

Part of the family glBind*

Signature

void glBindTexture(GLenum target, GLuint texture);

How it works

The GPU has several texture units (at least 16), each with its own slots for 2D, cube map, etc. glBindTexture places the texture into the unit selected by the last glActiveTexture call.

It serves two purposes: configuring the texture (glTexImage2D, glTexParameteri act on the bound texture) and using it for drawing (the sampler reads from its unit).

Parameters

targetGLenum

Kind of texture. Fixed at the first bind — a texture cannot change type later.

Common values

GL_TEXTURE_2D
Ordinary 2D image — the common case.
GL_TEXTURE_CUBE_MAP
Six square faces (skyboxes, reflections, point shadows).
GL_TEXTURE_2D_ARRAY
A stack of 2D layers of the same size.
GL_TEXTURE_3D
Volume texture.
GL_TEXTURE_2D_MULTISAMPLE
MSAA render target.
textureGLuint

Texture ID, or 0 to unbind.

Errors

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

GL_INVALID_OPERATION
texture was created with a different target.

Example

example.cpp
1glActiveTexture(GL_TEXTURE0);
2glBindTexture(GL_TEXTURE_2D, diffuse);
3glActiveTexture(GL_TEXTURE1);
4glBindTexture(GL_TEXTURE_2D, specular);
Official Khronos documentation