-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
69 lines (62 loc) · 2.02 KB
/
test.html
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
<html>
<title>Struct constructor/initializers highp bug.</title>
<canvas id="canvas"></canvas>
<script type="application/javascript">
"use strict";
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
var vs = gl.createShader(gl.VERTEX_SHADER);
var vs_code =`
attribute vec4 pos;
void main(){
gl_Position = pos;
}
`;
gl.shaderSource(vs, vs_code);
gl.compileShader(vs);
var fs = gl.createShader(gl.FRAGMENT_SHADER);
var fs_code =`
precision highp float;
struct Test {
vec3 color;
};
void main() {
vec3 color = vec3( 6378137.0, 0.0, 0.0 );
Test test;
test.color = color;
if (test.color.x == 6000000.0) {
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
} else {
gl_FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );
}
}
`;
gl.shaderSource(fs, fs_code);
gl.compileShader(fs);
var prg = gl.createProgram();
gl.attachShader(prg, vs);
gl.attachShader(prg, fs);
gl.linkProgram(prg);
gl.useProgram(prg);
var posLocation = gl.getAttribLocation(prg, 'pos');
gl.enableVertexAttribArray(posLocation);
var vertex = new Float32Array([
-0.8, -0.8, 0,
-0.8, 0.8, 0,
0.8, 0.8, 0,
0.8, -0.8, 0
]);
var index = new Uint8Array([0, 2, 1, 0, 3, 2]);
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertex, gl.STATIC_DRAW);
gl.vertexAttribPointer(posLocation, 3, gl.FLOAT, false, 0, 0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, index, gl.STATIC_DRAW);
gl.drawElements(gl.TRIANGLES, index.length, gl.UNSIGNED_BYTE, 0);
</script>
</html>