-
Notifications
You must be signed in to change notification settings - Fork 6
/
demo.js
37 lines (31 loc) · 974 Bytes
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var canvas = document.body.appendChild(document.createElement('canvas'))
var triangle = require('a-big-triangle')
var context = require('gl-context')
var fit = require('canvas-fit')
var Shader = require('gl-shader')
var glslify = require('glslify')
var start = Date.now()
window.addEventListener('resize', fit(canvas, window, 0.25), false)
Toy(function(gl) {
return Shader(gl
, glslify('./demo.vert')
, glslify('./demo.frag')
)
}, function(gl, shader) {
shader.uniforms.iResolution = [gl.drawingBufferWidth, gl.drawingBufferHeight]
shader.uniforms.iGlobalTime = (Date.now() - start) / 1000
})
// Extracted for gl-toy, need to do manual
// downsampling here :)
function Toy(shader, cb) {
var gl = context(canvas, render)
shader = shader(gl)
function render() {
var width = gl.drawingBufferWidth
var height = gl.drawingBufferHeight
gl.viewport(0, 0, width, height)
shader.bind()
cb(gl, shader)
triangle(gl)
}
}