Expand Minimize

bindTexture method

Binds a named texture object to a target.




WebGLRenderingContext.bindTexture(target, texture object);


target [in]

Type: Number

texture object [in]

Type: WebGLTexture

Either a reference to a texture object or null.

Return value

This method does not return a value.


WebGL errorDescription
gl.INVALID_ENUMIf target isn't one of the listed values..
gl.INVALID_OPERATIONIf texture was created with different target than target.



This example binds a texture to a WebGL context. For more info on this example, see Get started with WebGL.

// Create a texture object that will contain the image.
var texture = gl.createTexture();

// Bind the texture the target (TEXTURE_2D) of the active texture unit.
gl.bindTexture(gl.TEXTURE_2D, texture);

// Flip the image's Y axis to match the WebGL texture coordinate space.
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// Set the parameters so we can render any size image.        
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);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);

  // Upload the resized canvas image into the texture.
//    Note: a canvas is used here but can be replaced by an image object. 
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);

See also




© 2014 Microsoft