Skip to main content

Basic API

Set gl config

gl('count', 6) // or
gl({ count: 6 })

Set buffer object

// set uniform
gl.uniform('iTime', performance.now() / 1000) // or
gl.uniform({ iTime: performance.now() / 1000 })

// set attribute
gl.attribute('a_position', [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]) // or
gl.attribute({ a_position: [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1] })

Set mount and clean callback

// run when mount phase
gl('mount', () => {})

// run when clean phase
gl('clean', () => {})

more

Set frame callback

// Schedule an update
gl.frame((dt) => {})

// Start an update loop
gl.frame((dt) => true)

more

Render shorthands

gl.frame(() => {
        gl.clear() // ...... to call gl.clear(gl.COLOR_BUFFER_BIT)
        gl.viewport() // ... to call gl.viewport(0, 0, width, height)
        gl.drawArrays() // . to call gl.drawArrays(gl.TRIANGLES, 0, count)
        // or
        gl.drawElements() // to call gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_SHORT, 0)
})

Shader Inputs

uniform typeuniform keydescriptionavailability
uniform vec3iResolutionviewport resolution (in pixels)
uniform floatiTimeshader playback time (in seconds)
uniform floatiTimeDeltarender time (in seconds)
uniform floatiFrameRateshader frame rate
uniform intiFrameshader playback frame
uniform floatiChannelTime[4]channel playback time (in seconds)
uniform vec3iChannelResolution[4]channel resolution (in pixels)
uniform vec4iMousemouse pixel coords. xy: current (if MLB down), zw: click
uniform samplerXXiChannel0..3input channel. XX = 2D/Cube
uniform vec4iDate(year, month, day, time in seconds)
uniform floatiSampleRatesound sample rate (i.e., 44100)