|
1 | 1 | <!doctype html>
|
2 |
| -<html> |
| 2 | +<html lang="en"> |
3 | 3 | <head>
|
4 | 4 | <title>WebGL Demo</title>
|
5 |
| - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 | + <meta charset="utf-8"> |
6 | 6 | <link rel="stylesheet" href="../webgl.css" type="text/css">
|
| 7 | + </head> |
7 | 8 |
|
8 |
| - <script> |
9 |
| - var canvas; |
10 |
| - var gl; |
11 |
| - |
12 |
| - // |
13 |
| - // start |
14 |
| - // |
15 |
| - // Called when the canvas is created to get the ball rolling. |
16 |
| - // Figuratively, that is. There's nothing moving in this demo. |
17 |
| - // |
18 |
| - function start() { |
19 |
| - canvas = document.getElementById("glcanvas"); |
20 |
| - |
21 |
| - initWebGL(canvas); // Initialize the GL context |
22 |
| - |
23 |
| - // Only continue if WebGL is available and working |
24 |
| - if (!gl) { |
25 |
| - return; |
26 |
| - } |
27 |
| - |
28 |
| - gl.clearColor(0.0, 0.0, 0.0, 1.0); // Set clear color to black, fully opaque |
29 |
| - gl.clearDepth(1.0); // Clear everything |
30 |
| - gl.enable(gl.DEPTH_TEST); // Enable depth testing |
31 |
| - gl.depthFunc(gl.LEQUAL); // Near things obscure far things |
32 |
| - gl.clear(gl.COLOR_BUFFER_BIT); // Clear the color buffer with specified clear color |
33 |
| - } |
34 |
| - |
35 |
| - // |
36 |
| - // initWebGL |
37 |
| - // |
38 |
| - // Initialize WebGL, returning the GL context or null if |
39 |
| - // WebGL isn't available or could not be initialized. |
40 |
| - // |
41 |
| - function initWebGL() { |
42 |
| - gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); |
43 |
| - |
44 |
| - // If we don't have a GL context, give up now |
| 9 | + <body> |
| 10 | + <canvas id="glcanvas" width="640" height="480"></canvas> |
| 11 | + </body> |
45 | 12 |
|
46 |
| - if (!gl) { |
47 |
| - alert("Unable to initialize WebGL. Your browser may not support it."); |
48 |
| - } |
| 13 | + <script> |
| 14 | + main(); |
| 15 | + |
| 16 | + // |
| 17 | + // start here |
| 18 | + // |
| 19 | + function main() { |
| 20 | + const canvas = document.querySelector("#glcanvas"); |
| 21 | + // Initialize the GL context |
| 22 | + const gl = canvas.getContext("webgl"); |
| 23 | + |
| 24 | + // Only continue if WebGL is available and working |
| 25 | + if (!gl) { |
| 26 | + alert("Unable to initialize WebGL. Your browser or machine may not support it."); |
| 27 | + return; |
49 | 28 | }
|
50 |
| - </script> |
51 |
| - </head> |
52 | 29 |
|
53 |
| - <body onload="start()"> |
54 |
| - <canvas id="glcanvas" width="640" height="480"> |
55 |
| - Your browser doesn't appear to support the <code><canvas></code> element. |
56 |
| - </canvas> |
57 |
| - </body> |
| 30 | + // Set clear color to black, fully opaque |
| 31 | + gl.clearColor(0.0, 0.0, 0.0, 1.0); |
| 32 | + // Clear the color buffer with specified clear color |
| 33 | + gl.clear(gl.COLOR_BUFFER_BIT); |
| 34 | + } |
| 35 | + </script> |
58 | 36 | </html>
|
0 commit comments