-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (55 loc) · 1.59 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
Webgl Fundementals
</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
canvas#c {
height: 100vh;
width: 100vw;
display: block;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script id="2d-vertex-shader" type="x-shader/x-vertex">
//an attribute will receive data from a buffer
attribute vec2 a_position;
uniform vec2 u_resolution;
//all shaders have a main function
void main() {
// convert the position from pixels to 0.0 to 1.0
vec2 zeroToOne = a_position / u_resolution;
// convert from 0->1 to 0->2
vec2 zeroToTwo = zeroToOne * 2.0;
// convert from 0->2 to -1->+1
vec2 clipspace = zeroToTwo - 1.0;
// gl_Position is a special variab;e a vertex shader
// is responsible for setting
// flip clip space
gl_Position = vec4(clipspace * vec2(1, -1), 0, 1);
}
</script>
<script id="2d-fragment-shader" type="x-shader/x-fragment">
// fragment shaders dont have a default precision
// so we need to pick one. mediump is a good default.
precision mediump float;
uniform vec4 u_color;
void main () {
// gl_FragColor is a special variable a fragment
// shader is responsible for setting
gl_FragColor = u_color;
}
</script>
<script src="scripts/webglUtils.js"></script>
<script src="scripts/index.1.2.js"></script>
</body>
</html>