Skip to content

The "GL Texture" is a useful and efficient WebGL texture wrapper that simplifies handling textures in your projects. With this library, you can easily create, bind, and set texture data within your WebGL context. The installation is straightforward, and the library can be seamlessly integrated into your project using npm.

License

ahmerhh/WebGraphicLibrary-texture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GL Texture

WebGL texture wrapper.

WebGraphicLibrary texture is a WebGL texture wrapper that simplifies the creation and management of textures for use in WebGL applications

Installation

$ npm install --save @ahmerhh/WebGraphicLibrary-texture

Usage

import Texture from '@ahmerhh/WebGraphicLibrary-texture';

const texture = new Texture(gl, gl.TEXTURE_2D);

const img = document.createElement('img');

img.onload = () => {
	texture.bind(1);
	texture.setData(img);
}

img.src = '';

program.bind();
program.setUniform('uTexture', texture.bind(1));

API

texture = new Texture(gl, type)

texture = new Texture(gl, type, width, height)

texture = new Texture(gl, type, data)

Create a new texture, if no data is provided, the texture is empty.

  • gl is the WebGL context.
  • type is the texture type. Default is gl.TEXTURE_2D.
  • data can be an image, video or canvas.

texture.setData(data)

Set the texture data. The texture must be bound first.

texture.bind(1);
texture.setData(image);

texture.bind(unit)

Bind the texture to the given unit, and returns it. Default is 0. This allows to set a program uniform at the same time.

program.setUniform('uTextureA', textureA.bind(0));
program.setUniform('uTextureB', textureA.bind(1));

texture.dispose()

Delete instance. Calls gl.deleteTexture().

License

MIT, see LICENSE.md for more details.

Credits

Thanks to the amazing stackgl for the inspiration.

About

The "GL Texture" is a useful and efficient WebGL texture wrapper that simplifies handling textures in your projects. With this library, you can easily create, bind, and set texture data within your WebGL context. The installation is straightforward, and the library can be seamlessly integrated into your project using npm.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published