forked from imtumbleweed/WebGLTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebgltutorial2.php
More file actions
57 lines (45 loc) · 1.7 KB
/
Copy pathwebgltutorial2.php
File metadata and controls
57 lines (45 loc) · 1.7 KB
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
<!doctype html>
<html>
<head>
<title>Tutorial 3 - Load shaders from script tags</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src = '../js/jquery.js' type = 'text/javascript'></script>
<script src = '../js/ui.js' type = 'text/javascript'></script>
<script src = '../fx/gl.js'></script>
<script src = '../fx/shader.js'></script>
<!-- Standard vertex shader //-->
<script type = "glsl" id = "standard-vs">void main() {
gl_Position = vec4(0.0, 0.0, 0.0, 1); // x,y and z
gl_PointSize = 10.0;
}
</script>
<!-- Standard fragment shader //-->
<script type = "glsl" id = "standard-fs">void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // r,g and b
}
</script>
<script type = "text/javascript">
/* -- Gl functions -- */
var canvas = null;
$(document).ready(function() {
var gl = InitializeWebGL();
if (!gl)
console.log('Failed to set up WebGL.');
else { // Load a shader from script tags
var vs = document.getElementById("standard-vs").innerHTML;
var fs = document.getElementById("standard-fs").innerHTML;
var standardProgram = InitializeShader(gl, vs, fs);
gl.useProgram(standardProgram);
gl.drawArrays(gl.POINT, 0, 1);
}
});
</script>
</head>
<style>
#fx { position: relative; margin: 0 auto; width: 1000px; height: 500px; border: 1px solid gray; }
#gl { width: 800px; height: 600px; }
</style>
<body style = "background: #505050; padding: 32px;">
<canvas id = "gl" width = "800" height = "600"></canvas>
</body>
</html>