How to initialise WebGL

From webglcookbook
Revision as of 20:20, 11 February 2010 by Giles (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

WebGL content is displayed in an HTML canvas element. Use the following code to get a WebGL context for a given canvas.

 var gl;
 function initGL(canvas) {
   try {
     gl = canvas.getContext("experimental-webgl");
     gl.viewport(0, 0, canvas.width, canvas.height);
   } catch(e) {
   }
   if (!gl) {
     alert("Could not initialise WebGL, sorry :-(");
   }
 }

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox