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

1.1.12 • Public • Published

desenha

A barebones WebGL library. Inspired by https://webglfundamentals.org/ and OGL. You probably shouldn't use this.

Example :

import { Desenhador, Cube } from "desenha"

// Renderer
const { gl, draw } = new Desenhador()

// Shaders
const vertex = `
    attribute vec4 aPosition;

    uniform mat4 uModelMatrix;
    uniform mat4 uProjectionMatrix;
    
    void main(void) {
        gl_Position = uProjectionMatrix * uModelMatrix * aPosition;
    }
`
const fragment = `
    void main(void) {
        gl_FragColor = vec4(vec3(1.,0.,0.),1.);
    }
`

// These will get drawn at render time
const meshes = []

// Init mesh
const cube = new Cube({
    name: 'Red cube',
    shaders: [vertex, fragment],
    locationNames: {
        attributes: ['aPosition'],
        uniforms: ['uProjectionMatrix', 'uModelMatrix']
    },
    parameters: {
        position: { x: 0, y: 0, z: -10 }
    },
    gl
})

// Executes callback each frame after being drawn
cube.addOnDrawCallback((mesh, deltaTime) => {
    mesh.rotation[0] += 0.01
    mesh.rotation[1] += 0.01
})

meshes.push(cube)

// Render loop
let then = 0;
const update = (now: number) => {
    const deltaTime = now - then;
    then = now;

    draw(meshes, deltaTime);

    requestAnimationFrame(update);
}

requestAnimationFrame(update);

Red cube

More examples available under /examples:

  • Fullscreen shader
  • OBJ model and texture loading

What does 'desenha' mean ?

It means 'draw' in Portuguese.

Readme

Keywords

Package Sidebar

Install

npm i desenha

Weekly Downloads

1

Version

1.1.12

License

ISC

Unpacked Size

680 kB

Total Files

47

Last publish

Collaborators

  • michael.dll