forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.js
58 lines (49 loc) · 948 Bytes
/
elements.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
51
52
53
54
55
56
57
58
/*
tags: basic, lines
<p> This example demonstrates how you can use `elements` to draw lines. </p>
*/
const regl = require('../regl')()
regl.clear({
color: [0, 0, 0, 1],
depth: 1
})
var lineWidth = 3
if (lineWidth > regl.limits.lineWidthDims[1]) {
lineWidth = regl.limits.lineWidthDims[1]
}
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: (new Array(5)).fill().map((x, i) => {
var theta = 2.0 * Math.PI * i / 5
return [ Math.sin(theta), Math.cos(theta) ]
})
},
uniforms: {
color: [1, 0, 0, 1]
},
elements: [
[0, 1],
[0, 2],
[0, 3],
[0, 4],
[1, 2],
[1, 3],
[1, 4],
[2, 3],
[2, 4],
[3, 4]
],
lineWidth: lineWidth
})()