Giter Site home page Giter Site logo

ahmerhh / webgraphiclibrary-texture Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 23.27 MB

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: MIT License

JavaScript 100.00%
wgl

webgraphiclibrary-texture's Introduction

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.

webgraphiclibrary-texture's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.