Back to Content

WebGLRenderingContext: createTexture() method

files/en-us/web/api/webglrenderingcontext/createtexture/index.md

latest1006 B
Original Source

{{APIRef("WebGL")}}{{AvailableInWorkers}}

The WebGLRenderingContext.createTexture() method of the WebGL API creates and initializes a {{domxref("WebGLTexture")}} object.

Syntax

js-nolint
createTexture()

Parameters

None.

Return value

A {{domxref("WebGLTexture")}} object to which images can be bound to.

Examples

See also the WebGL tutorial on Using textures in WebGL.

Creating a texture

js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const texture = gl.createTexture();

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("WebGLRenderingContext.bindTexture()")}}
  • {{domxref("WebGLRenderingContext.deleteTexture()")}}
  • {{domxref("WebGLRenderingContext.isTexture()")}}
  • {{domxref("WebGLRenderingContext.texImage2D()")}}