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
59
60
61
62
63
64
65
66
67
68
69
|
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Цветни точки</title>
<script src="webgl-fmi.js"></script>
<script id="vshader" type="x-shader/x-vertex">
attribute vec2 aXY;
attribute float aGreen;
varying float vGreen;
void main ()
{
gl_Position = vec4(aXY,0,1);
vGreen = aGreen;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision lowp float;
varying float vGreen;
void main( )
{
gl_FragColor = vec4(1,vGreen,0,1);
}
</script>
<script>
function start( )
{
gl = getContext("picasso");
glprog = getProgram("vshader","fshader");
aXY = gl.getAttribLocation(glprog,"aXY");
aGreen = gl.getAttribLocation(glprog,"aGreen");
gl.clearColor(1,1,1,1);
gl.clear(gl.COLOR_BUFFER_BIT);
var n = 100000;
var points = [];
for (var i = 0; i < n; i++)
points.push(random(-1, 1), random(-1, 1), random(0, 1));
var buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(points), gl.STATIC_DRAW);
gl.vertexAttribPointer(aXY, 2, gl.FLOAT, false, 3*FLOATS, 0*FLOATS);
gl.vertexAttribPointer(aGreen, 1, gl.FLOAT, false, 3*FLOATS, 2*FLOATS);
gl.enableVertexAttribArray(aXY);
gl.enableVertexAttribArray(aGreen);
gl.drawArrays(gl.POINTS, 0, n);
}
</script>
</head>
<body onload="start()">
<h2>Цветни точки</h2>
<noscript>
Искаме JavaScript, но няма!
</noscript>
<canvas id="picasso" width="600" height="400" style="border: solid;">
Искаме canvas, но няма!
</canvas>
</body>
|