0.2.3 • Published 7 months ago

triangular v0.2.3

Weekly downloads
10
License
UNLICENSED
Repository
github
Last release
7 months ago

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

0.2.3

7 months ago

0.2.2

7 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

4 years ago

0.1.0

4 years ago