1.1.12 • Published 8 months ago

desenha v1.1.12

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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.

1.1.1

9 months ago

1.1.8

8 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.4

8 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.12

8 months ago

1.1.11

8 months ago

1.1.10

8 months ago

1.1.0

12 months ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.10

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago