This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

glkit

0.0.2065 • Public • Published
import { WebGL } from 'glkit';

const CTX = new WebGL();
const gl = CTX.WebGLRenderingContext;
const { TRIANGLES } = gl;

const camera = new CTX.Obj({
  draw() {
    camera.updateMatrix();
    camera.viewMatrix.getInverse(camera.matrix.arr);
  }
});
camera.projectionMatrix = new CTX.Mat4({ name: 'projectionMatrix' });
camera.projectionMatrix.makePerspective();
camera.viewMatrix = new CTX.Mat4({ name: 'viewMatrix' });
camera.translateZ(-100);
camera.draw();

const material = new CTX.Material({
  uniforms: [
    camera.projectionMatrix,
    camera.viewMatrix,
  ],
  vertexShader:
    `
    precision ${ CTX.maxPrecision.vs.float } float;
    attribute vec3 position;
    uniform mat4 projectionMatrix;
    uniform mat4 viewMatrix;
    void main() {
      gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.);
    }
    `,
  fragmentShader:
    `
    precision ${ CTX.maxPrecision.fs.float } float;
    void main() {
      gl_FragColor = vec4(1.);
    }
    `,
});

const { program } = material;

const position = new CTX.VBO({
  name: 'position',
  content: new Float32Array([ ... ]),
  location: 0,
});

const verticesNum = position.content.length / 3;

const triangle = new CTX.Obj({
  draw() {
    gl.useProgram(program);
    position.enable();
    gl.drawArrays(TRIANGLES, 0, verticesNum);
  },
});

triangle.draw();

Dependents (0)

Package Sidebar

Install

npm i glkit

Weekly Downloads

118

Version

0.0.2065

License

MIT

Unpacked Size

83.2 kB

Total Files

6

Last publish

Collaborators

  • dsbelov