Detecting WebGL support

Not all browsers currently support WebGL. When you create a page that uses the THREE.WebGLRenderer object, it is a good idea to make sure that the browser supports WebGL. If a browser doesn't support it, this will result in all kinds of strange JavaScript errors in the JavaScript console and an empty screen for the end user. To make sure that your WebGL projects work as expected, we'll explain how to detect WebGL support in a browser in this recipe.

Getting ready

In this recipe, as an example, we will use the 01.04-detect-webgl-support.html file, which you can find in the sources provided with this book. If you open this file, you'll see the following result if your browser doesn't support WebGL:

Let's take a look at the recipe ...

Get Three.js Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.