Graphics Reference
In-Depth Information
As you can see, we just create a number of div elements that are currently
hidden. When we detect that WebGL isn't supported this will be shown by the
two div elements by changing their visibility.
6. Next, let's take a look at the JavaScript you need to add to detect WebGL.
We'll create the following function for it:
// loosely based on the
http://get.webgl.org function
detectWebGL() {
// first create a canvas element
var testCanvas =
document.createElement("canvas");
// and from that canvas get the
webgl context
var gl = null;
// if exceptions are thrown,
indicates webgl is null
try {
gl =
testCanvas.getContext("webgl");
} catch (x) {
gl = null;
}
// if still null try experimental
if (gl == null) {
try {
gl =
testCanvas.getContext("experimental-webgl");
} catch (x) {
gl = null;
}
}
// if webgl is all good return true;
Search WWH ::




Custom Search