TexturesGL 1.0

glTexParameteri

Sets how the bound texture is sampled: filtering, wrapping, comparison.

Signature

void glTexParameteri(GLenum target, GLenum pname, GLint param);

How it works

Texture coordinates rarely land exactly on a texel center, and they can go outside 0–1. These parameters decide what happens: blend neighboring texels (GL_LINEAR) or pick the nearest (GL_NEAREST); repeat, mirror or clamp outside the edges.

The default minification filter uses mipmaps. If your texture has none, it is "incomplete" and samples as black — set GL_TEXTURE_MIN_FILTER to GL_LINEAR or generate mipmaps.

u = -1u = 0u = 1u = 2GL_REPEATGL_MIRRORED_REPEATGL_CLAMP_TO_EDGEGL_CLAMP_TO_BORDER
One texture sampled from u = −1 to u = 2; the middle tile (0 to 1) is the texture itself. REPEAT tiles it, MIRRORED_REPEAT flips every other copy, CLAMP_TO_EDGE stretches the edge pixels outward, CLAMP_TO_BORDER uses a fixed border colour (GL_TEXTURE_BORDER_COLOR).

Parameters

targetGLenum

Target of the bound texture (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP…).

pnameGLenum

Which parameter.

Common values

GL_TEXTURE_MIN_FILTER
Filter when the texture is shrunk. GL_LINEAR_MIPMAP_LINEAR (trilinear) needs mipmaps.
GL_TEXTURE_MAG_FILTER
Filter when magnified: GL_LINEAR (smooth) or GL_NEAREST (pixel art).
GL_TEXTURE_WRAP_S / _T / _R
What happens outside 0–1: GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER.
GL_TEXTURE_COMPARE_MODE
GL_COMPARE_REF_TO_TEXTURE turns a depth texture into a shadow sampler.
GL_TEXTURE_MAX_LEVEL
Highest mip level that may be used.
paramGLint

The value (an enum such as GL_LINEAR or GL_REPEAT).

Tips & pitfalls

  • GL_TEXTURE_MAG_FILTER only accepts GL_LINEAR or GL_NEAREST — mipmaps are never used for magnification.

  • Use GL_CLAMP_TO_EDGE for cube maps and screen-space textures to avoid visible seams.

Errors

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

GL_INVALID_ENUM
pname or param is not valid (e.g. a mipmap filter for MAG_FILTER).

Example

example.cpp
1glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
3glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
4glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Official Khronos documentation