createTexture()
ts
function createTexture(gl, options?): WebGLTexture;Defined in: createTexture.js:52
Creates a 2D texture from an image source (img: an image, canvas, video or ImageBitmap that has already loaded), or from data of width x height pixels: a typed array, or null for an empty texture.
Float types (gl.FLOAT, gl.HALF_FLOAT) get a sized internal format, e.g. RG + FLOAT -> RG32F. Mipmaps default on only for gl.UNSIGNED_BYTE textures, and 32-bit float textures default to NEAREST filtering where linear filtering of them isn't supported.
flipY flips the image on upload, so row 0 of an image or canvas lands at the bottom, where texture coordinate y = 0 is.
Parameters
| Parameter | Type | Description |
|---|---|---|
gl | WebGL2RenderingContext | The WebGL2 context. |
options? | TextureOptions | See TextureOptions. |
Returns
WebGLTexture
Example
ts
const glyphs = createTexture(gl, {
data: new Float32Array(1024 * rows * 2), width: 1024, height: rows,
format: gl.RG, type: gl.FLOAT,
});