triangular
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

Triangular ▲

Type safe wrapper for WebGL.

Install

yarn add triangular

Or

npm i triangular

Usage

import { createGL } from 'triangular';

const canvas = document.body.appendChild(document.createElement('canvas'));

const gl = createGL(canvas);

const positionBuffer = gl.createAttributeBuffer('vec2');
positionBuffer.bufferData([0, 1, 1, -1, -1, -1]);

const program = gl.createProgram({
  attributes: { position: 'vec2' },
  uniforms: {},
  fragmentUniforms: {},
  varying: { color: 'vec2' },
  textures: {},
  vertexShaderSource: ({ attributes, varying }) => `
    void main() {
      gl_Position = vec4(${attributes.position}.xy, 0, 1);
      ${varying.color} = (gl_Position.xy + vec2(1,1)) / vec2(2,2);
    }
  `,
  fragmentShaderSource: ({ varying }) => `
    void main() {
      gl_FragColor = vec4(0, ${varying.color}, 1);
    }
  `,
});

gl.clear();

program.drawTriangles({
  uniforms: {},
  fragmentUniforms: {},
  attributeBuffers: { position: positionBuffer },
  textureBuffers: {},
});

Edit triangular-example

Readme

Keywords

Package Sidebar

Install

npm i triangular

Weekly Downloads

1

Version

0.2.3

License

UNLICENSED

Unpacked Size

24.7 kB

Total Files

10

Last publish

Collaborators

  • mmmurray