Skip to content

Textures

loadTexture() ​

ts
function loadTexture(
   gl, 
   url, 
   options?
): Promise<WebGLTexture>;

Defined in: loadTexture.js:31

Loads an image and resolves with a texture made from it. options are passed to createTexture. Cross-origin images need CORS headers.

Pass signal to give up: if it's aborted before the image has loaded, no texture is made and the promise rejects with the signal's reason.

Parameters ​

ParameterTypeDescription
glWebGL2RenderingContextThe WebGL2 context.
urlstring-
options?LoadTextureOptionsSee LoadTextureOptions.

Returns ​

Promise<WebGLTexture>

Example ​

ts
const texture = await loadTexture(gl, "noise.png", { wrapS: gl.REPEAT, wrapT: gl.REPEAT });