Texture wrapping

In the previous section, we used texParameteri to set the filter mode for textures, but as you might expect from the generic function name, that's not all that it can do. Another texture behavior that we can manipulate is the texture wrapping mode.

Texture wrapping describes the behavior of the sampler when the texture coordinates fall outside the range of 0-1.

The wrapping mode can be set independently for both the S and T coordinates, so changing the wrapping mode typically takes two calls:

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

Here we're setting both the S and T wrapping modes for the currently bound texture to CLAMP_TO_EDGE, the ...

Get WebGL Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.