forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webgl-color-test.html
80 lines (63 loc) · 1.79 KB
/
webgl-color-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
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="webgl-utils.js"></script>
<script type="text/javascript">
/* Color Test
*
* Clear the four quadrants of the canvas as follows:
* +------+------+
* | red |green |
* | | |
* +------+------+
* | blue |white |
* | | |
* +------+------+
*
* This is for checking that we're getting the right colors when
* we ask for them. This combined with the Orientation test assure
* that we are getting the correct colors in the correct places.
*/
"use strict";
function renderGL(gl) {
gl.enable(gl.SCISSOR_TEST);
gl.scissor(0, 128, 128, 128);
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.scissor(128, 128, 128, 128);
gl.clearColor(0.0, 1.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.scissor(0, 0, 128, 128);
gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.scissor(128, 0, 128, 128);
gl.clearColor(1.0, 1.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.finish();
}
function renderBackup(canvas) {
var context = canvas.getContext("2d");
context.fillStyle = "rgba(255, 0, 0, 1.0)";
context.fillRect(0, 0, 128, 128);
context.fillStyle = "rgba(0, 255, 0, 1.0)";
context.fillRect(128, 0, 128, 128);
context.fillStyle = "rgba(0, 0, 255, 1.0)";
context.fillRect(0, 128, 128, 128);
context.fillStyle = "rgba(255, 255, 255, 1.0)";
context.fillRect(128, 128, 128, 128);
}
function onLoad() {
var canvas = document.getElementById("canvas");
var gl = initGL(canvas);
if (gl)
renderGL(gl);
else
renderBackup(canvas);
}
</script>
</head>
<body onload="onLoad();">
<canvas id="canvas" width="256" height="256"></canvas>
</body>
</html>