Graphics Reference
In-Depth Information
if (gl) {
return true;
} else {
return false;
}
}
As you can see, we create an HTML canvas element and then try to create
a WebGL context with the getContext function. If this fails, the gl variable
is set to null but if it succeeds, the gl variable will contain the WebGL con-
text. If the gl variable isn't null, it will return true. On the hand, if it is, it will
return false.
7. Now that we're able to detect whether a browser supports WebGL or not,
we'll use this function to show a pop up. For this recipe, we'll also show you
a pop up when WebGL is supported:
var hasGl = detectWebGL();
if (hasGl) {
showLightbox("WebGL is supported");
} else {
showLightbox("WebGL is
not-supported");
}
function showLightbox(message) {
var lightBox =
document.getElementById('light');
lightBox.style.display = 'block';
var fadeBox =
document.getElementById('fade');
fadeBox.style.display = 'block'
var msg =
document.getElementById('message');
msg.textContent = message;
Search WWH ::




Custom Search