Game Development Reference
In-Depth Information
Ironically, Microsoft can help some old video cards work with WebGL on Windows machines. The ANGLE
(Almost Native Graphics Layer Engine) project translates OpenGL ES 2.0 API calls to DirectX 9 API calls.
The result is that graphics cards that only support OpenGL 1.5 (OpenGL ES 1.0) can still run WebGL.
Testing for WebGL support
There are several sites to test your browser's support of WebGL. Two of these are
http://doesmybrowsersupportwebgl.com , which on success displays the attributes of your browser and
its maximum WebGL capabilities, and http://get.webgl.org , which displays a spinning cube if your
browser supports WebGL. We can also programmatically check for WebGL support using modernizr
( www.modernizr.com ).
Listing 7-1 shows a simple script that will alert you if WebGL is not initialized properly.
Listing 7-1. Testing for WebGL Support
<!DOCTYPE html>
<html>
<head>
<style>
body{ background: gray; }
canvas{ background: white; }
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var gl;
try {
gl = canvas.getContext("experimental-webgl");
} catch (e) {
alert(e);
}
if (!gl) {
alert("Error trying to initialise WebGL. Try get.webgl.org");
} else {
gl.clearColor(0.0, 0.7, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
}
</script>
</body>
</html>
Note Once the WebGL specification is finalized, the canvas context will be "webgl"
instead of "experimental-webgl".
When support for WebGL is not found, then we should fall back to a different technology if possible (such
as a '2D' canvas context, a static image, etc.) and/or display an appropriate error message to the user.
 
Search WWH ::




Custom Search