forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.js
50 lines (41 loc) · 1.03 KB
/
basic.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
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
tags: basic
<p> This example is a simple demonstration of how to use regl to draw a triangle. </p>
*/
// The default method exposed by the module wraps a canvas element
const regl = require('../regl')()
// This clears the color buffer to black and the depth buffer to 1
regl.clear({
color: [0, 0, 0, 1],
depth: 1
})
// In regl, draw operations are specified declaratively using. Each JSON
// command is a complete description of all state. This removes the need to
// .bind() things like buffers or shaders. All the boilerplate of setting up
// and tearing down state is automated.
regl({
// In a draw call, we can pass the shader source code to regl
frag: `
precision mediump float;
uniform vec4 color;
void main () {
gl_FragColor = color;
}`,
vert: `
precision mediump float;
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0, 1);
}`,
attributes: {
position: [
[-1, 0],
[0, -1],
[1, 1]
]
},
uniforms: {
color: [1, 0, 0, 1]
},
count: 3
})()