-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch1_GL_Context.html
More file actions
56 lines (48 loc) · 1.17 KB
/
Copy pathch1_GL_Context.html
File metadata and controls
56 lines (48 loc) · 1.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebGL Beginner's Guide - Setting up the canvas</title>
</head>
<body onLoad="getGLContext()">
<canvas id="canvas-element-id" width="800" height="600">
Your browser does not support HTML5
</canvas>
<style type="text/css">
canvas {
border: 2px dotted blue;
}
</style>
<script>
var gl = null;
function getGLContext() {
var canvas = document.getElementById("canvas-element-id");
if (canvas == null) {
alert("there is no canvas on this page");
return;
}
var names = [
"webgl",
"experimental-webgl",
"webkit-3d",
"moz-webgl"
];
for (var i = 0; i < names.length; ++i) {
try {
gl = canvas.getContext(names[i]);
}
catch (e) { }
if (gl) break;
}
if (gl == null) {
alert("WebGL is not available");
}
else {
alert("Hooray! You got a WebGL context");
}
}
</script>
</body>
</html>