1. Diego Cantor
  2. WebGL Beginner's Guide - Code


WebGL Beginner's Guide - Code / 1727_01 / ch1_GL_Context.html

	 <title> WebGL Beginner's Guide - Checking the WebGL Context </title>
	 <style type="text/css">
	 canvas {border: 2px dotted blue;}
		var gl = null;
		function getGLContext(){
			var canvas = document.getElementById("canvas-element-id");
			if (canvas == null){
				alert("there is no canvas on this page");
			var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
            for (var i = 0; i < names.length; ++i) {
                try {
                    gl = canvas.getContext(names[i]);
                catch(e) {}
                if (gl) break;

			if (gl == null){
				alert("WebGL is not available");
				alert("Hooray! You got a WebGL context");
<body onLoad="getGLContext()">
<canvas id="canvas-element-id" width="800" height="600">
Your browser does not support the HTML5 canvas element.