@3d-smile/glkit

@3d-smile/glkit

Usage no npm install needed!

<script type="module">
  import 3dSmileGlkit from 'https://cdn.skypack.dev/@3d-smile/glkit';
</script>

README

@3d-smile/glkit

// Hello, triangle!

import { WebGL } from '@3d-smile/glkit';

const CTX = new WebGL();
const gl = CTX.WebGLRenderingContext;

new CTX.VBO({ srcData: new Float32Array([ -10, -10, -10, 0, 10, -10, 10, -10, -10 ]).buffer }).bind();

new CTX.Program({
  VS: (prog) => `
    precision ${ CTX.maxShaderPrecision.vs.float } float;
    ${ new CTX.VertexAttrib().enable().pointer().inject(prog, 'position') }
    ${ new CTX.Mat4().makePerspectiveProjectionMatrix().injectUniform(prog, 'projectionMatrix') }
    void main() {
      gl_Position = projectionMatrix * vec4(position, 1.0);
    }`,

  FS: () => `
    precision ${ CTX.maxPrecision.fs.float } float;
    void main() {
      gl_FragColor = vec4(1.0);
    }`,
}).compose().use().init();

gl.drawArrays(gl.TRIANGLES, 0, 3);