WebGL

  • Revision slug: WebGL
  • Revision title: WebGL
  • Revision id: 386085
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{DevDerbyPromoHeader('WebGL')}}

WebGL brings 3D graphics to the Web by introducing an API that closely conforms to OpenGL ES 2.0 that can be used in HTML5 {{HTMLElement("canvas")}} elements. Support for WebGL is present in Firefox 4+, Google Chrome 9+, Opera 12+ and Safari 5.1+.

Development topics

Getting started with WebGL
How to set up a WebGL context.
Adding 2D content to a WebGL context
How to render simple flat shapes using WebGL.
Using shaders to apply color in WebGL
Demonstrates how to add color to shapes using shaders.
Animating objects with WebGL
Shows how to rotate and translate objects to create simple animations.
Creating 3D objects using WebGL
Shows how to create and animate a 3D object (in this case, a cube).
Using textures in WebGL
Demonstrates how to map textures onto the faces of an object.
Lighting in WebGL
How to simulate lighting effects in your WebGL context.
Animating textures in WebGL
Shows how to animate textures; in this case, by mapping an Ogg video onto the faces of a rotating cube.
WebGL best practices
Tips and suggestions to improve your WebGL content.
Cross-domain textures
Information about loading textures from domains other than the one from which your content was loaded.
Using extensions
How to use extensions that are available in WebGL.
WebGL Specification
The WebGL specification.
Khronos WebGL site
The main web site for WebGL at the Khronos Group.
Learning WebGL
A site with tutorials on how to use WebGL.
WebGL Fundamentals
A basic tutorial with fundamentals of WebGL.
The WebGL Cookbook
A web site with handy recipes for writing WebGL code.
Planet WebGL
A feed aggregator for people involved in the WebGL community.
ewgl-matrices
A blazing fast matrix library for WebGL
glMatrix
JavaScript Matrix and Vector library for High Performance WebGL apps
mjs
A JavaScript vector and matrix math library, optimized for WebGL usage.
Sylvester
An open source library for manipulating vectors and matrices. Not optimized for WebGL but extremely robust.
WebGL playground
An online tool for creating and sharing WebGL projects. Good for quick prototyping and experimenting.

Browser compatibility

{{CompatibilityTable}}
Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatGeckoDesktop("2.0")}} 9 {{CompatNo}} 12 5.1
Context name experimental-webgl experimental-webgl n/a experimental-webgl experimental-webgl
OES_texture_float {{CompatGeckoDesktop("6.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_standard_derivatives {{CompatGeckoDesktop("10.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_texture_filter_anisotropic {{CompatGeckoDesktop("13.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_s3tc {{CompatGeckoDesktop("15.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
drawingBufferWidth and drawingBufferHeight attributes {{CompatGeckoDesktop("9.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Firefox Mobile (Gecko) Chrome for Android IE Mobile Opera Mobile Safari Mobile
Basic support 4 25 (experiment) {{CompatNo}} 12 {{CompatNo}}
Context name experimental-webgl experimental-webgl {{CompatNo}} experimental-webgl {{CompatNo}}
drawingBufferWidth and drawingBufferHeight attributes {{CompatGeckoMobile("9.0")}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_float {{CompatGeckoMobile("6.0")}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_standard_derivatives {{CompatGeckoMobile("10.0")}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_texture_filter_anisotropic {{CompatGeckoMobile("13.0")}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_element_index_uint {{CompatUnknown}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_vertex_array_object {{CompatUnknown}} 25 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_s3tc {{CompatGeckoMobile("15.0")}} 25
prefixed with WEBKIT_
{{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBKIT_EXT_texture_filter_nisotropic {{CompatNo}} 25 {{CompatNo}} {{CompatNo}} {{CompatUnknown}}

Compatibility notes

In addition to the browser, the GPU itself also needs to support the feature. So, for example, S3 Texture Compression (S3TC) is only available on Tegra-based tablets.

Gecko notes

WebGL debugging and testing

Starting with Gecko 10.0 {{geckoRelease("10.0")}}, there are two preferences available which let you control the capabilities of WebGL for testing purposes:

webgl.min_capability_mode
A Boolean property that, when true, enables a minimum capability mode. When in this mode, WebGL is configured to only support the bare minimum feature set and capabilities required by the WebGL specification. This lets you ensure that your WebGL code will work on any device or browser, regardless of their capabilities. This is false by default.
webgl.disable_extensions
A Boolean property that, when true, disables all WebGL extensions. This is false by default.
{{HTML5ArticleTOC}}

Revision Source

<div>{{DevDerbyPromoHeader('WebGL')}}</div>

<p>WebGL brings 3D graphics to the Web by introducing an API that closely conforms to OpenGL ES 2.0 that can be used in HTML5 {{HTMLElement("canvas")}} elements. Support for WebGL is present in <a href="/en-US/docs/Firefox_4_for_developers" title="Firefox 4 for developers">Firefox 4</a>+, <a href="http://www.google.com/chrome/" title="http://www.google.com/chrome/">Google Chrome</a> 9+, <a href="http://www.opera.com/" title="http://www.opera.com/">Opera </a>12+ and <a href="http://www.apple.com/fr/safari/" title="http://www.apple.com/fr/safari/">Safari </a>5.1+.</p>
<div class="cleared row topicpage-table">
  <div class="section">
    <h2 class="Documentation" id="Development_topics">Development topics</h2>
    <dl>
      <dt><a href="/en-US/docs/WebGL/Getting_started_with_WebGL" title="WebGL/Getting started with WebGL">Getting started with WebGL</a></dt>
      <dd>How to set up a WebGL context.</dd>
      <dt><a href="/en-US/docs/WebGL/Adding_2D_content_to_a_WebGL_context" title="WebGL/Adding 2D content to a WebGL context">Adding 2D content to a WebGL context</a></dt>
      <dd>How to render simple flat shapes using WebGL.</dd>
      <dt><a href="/en-US/docs/WebGL/Using_shaders_to_apply_color_in_WebGL" title="WebGL/Using shaders to apply color in WebGL">Using shaders to apply color in WebGL</a></dt>
      <dd>Demonstrates how to add color to shapes using shaders.</dd>
      <dt><a href="/en-US/docs/WebGL/Animating_objects_with_WebGL" title="WebGL/Animating objects with WebGL">Animating objects with WebGL</a></dt>
      <dd>Shows how to rotate and translate objects to create simple animations.</dd>
      <dt><a href="/en-US/docs/WebGL/Creating_3D_objects_using_WebGL" title="WebGL/Creating 3D objects using WebGL">Creating 3D objects using WebGL</a></dt>
      <dd>Shows how to create and animate a 3D object (in this case, a cube).</dd>
      <dt><a href="/en-US/docs/WebGL/Using_textures_in_WebGL" title="WebGL/Using textures in WebGL">Using textures in WebGL</a></dt>
      <dd>Demonstrates how to map textures onto the faces of an object.</dd>
      <dt><a href="/en-US/docs/WebGL/Lighting_in_WebGL" title="WebGL/Lighting in WebGL">Lighting in WebGL</a></dt>
      <dd>How to simulate lighting effects in your WebGL context.</dd>
      <dt><a href="/en-US/docs/WebGL/Animating_textures_in_WebGL" title="WebGL/Animating textures in WebGL">Animating textures in WebGL</a></dt>
      <dd>Shows how to animate textures; in this case, by mapping an Ogg video onto the faces of a rotating cube.</dd>
      <dt><a href="/en-US/docs/WebGL/WebGL_best_practices" title="WebGL/WebGL best practices">WebGL best practices</a></dt>
      <dd>Tips and suggestions to improve your WebGL content.</dd>
      <dt><a href="/en-US/docs/WebGL/Cross-Domain_Textures" title="WebGL/Cross-Domain Textures">Cross-domain textures</a></dt>
      <dd>Information about loading textures from domains other than the one from which your content was loaded.</dd>
      <dt><a href="/en-US/docs/WebGL/Using_Extensions" title="WebGL/Using_Extensions">Using extensions</a></dt>
      <dd>How to use extensions that are available in WebGL.</dd>
    </dl>
  </div>
  <div class="section">
    <h2 class="Related_Topics" id="Resources">Resources</h2>
    <dl>
      <dt><a class="link-https" href="https://www.khronos.org/registry/webgl/specs/1.0/" title="https://www.khronos.org/registry/webgl/specs/1.0/">WebGL Specification</a></dt>
      <dd>The WebGL specification.</dd>
      <dt><a href="http://www.khronos.org/webgl/" title="http://www.khronos.org/webgl/">Khronos WebGL site</a></dt>
      <dd>The main web site for WebGL at the Khronos Group.</dd>
      <dt><a href="http://learningwebgl.com/blog/?page_id=1217" title="http://learningwebgl.com/blog/">Learning WebGL</a></dt>
      <dd>A site with tutorials on how to use WebGL.</dd>
      <dt><a href="http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/" title="http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/">WebGL Fundamentals</a></dt>
      <dd>A basic tutorial with fundamentals of WebGL.</dd>
      <dt><a href="http://learningwebgl.com/cookbook/index.php/" title="http://learningwebgl.com/cookbook/index.php/">The WebGL Cookbook</a></dt>
      <dd>A web site with handy recipes for writing WebGL code.</dd>
      <dt><a href="http://planet-webgl.org/" title="http://planet-webgl.org/">Planet WebGL</a></dt>
      <dd>A feed aggregator for people involved in the WebGL community.</dd>
      <dt><a href="http://code.google.com/p/ewgl-matrices/" title="http://code.google.com/p/ewgl-matrices/">ewgl-matrices</a></dt>
      <dd>A blazing fast matrix library for WebGL</dd>
      <dt><a class="link-https" href="https://github.com/toji/gl-matrix" title="https://github.com/toji/gl-matrix">glMatrix</a></dt>
      <dd>JavaScript Matrix and Vector library for High Performance WebGL apps</dd>
      <dt><a href="http://code.google.com/p/webgl-mjs/" title="http://code.google.com/p/webgl-mjs/">mjs</a></dt>
      <dd><span>A JavaScript vector and matrix math library, optimized for WebGL usage.</span></dd>
      <dt><a href="http://sylvester.jcoglan.com/" title="http://sylvester.jcoglan.com/">Sylvester</a></dt>
      <dd>An open source library for manipulating vectors and matrices. Not optimized for WebGL but extremely robust.</dd>
      <dt><a href="http://webglplayground.net" title="http://webglplayground.net">WebGL playground</a></dt>
      <dd>An online tool for creating and sharing WebGL projects. Good for quick prototyping and experimenting.</dd>
    </dl>
  </div>
</div>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox (Gecko)</th>
        <th>Chrome</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatGeckoDesktop("2.0")}}</td>
        <td>9</td>
        <td>{{CompatNo}}</td>
        <td>12</td>
        <td>5.1</td>
      </tr>
      <tr>
        <td>Context name</td>
        <td><code>experimental-webgl</code></td>
        <td><code>experimental-webgl</code></td>
        <td>n/a</td>
        <td><code>experimental-webgl</code></td>
        <td><code>experimental-webgl</code></td>
      </tr>
      <tr>
        <td><a href="http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt" title="http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt"><code>OES_texture_float</code></a></td>
        <td>{{CompatGeckoDesktop("6.0")}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="http://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/" title="http://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/"><code>OES_standard_derivatives</code></a></td>
        <td>{{CompatGeckoDesktop("10.0")}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="/en-US/docs/WebGL/Using_Extensions#EXT_texture_filter_anisotropic" title="WebGL/Using_Extensions#EXT_texture_filter_anisotropic"><code>EXT_texture_filter_anisotropic</code></a></td>
        <td>{{CompatGeckoDesktop("13.0")}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="/en-US/docs/WebGL/Using_Extensions#WEBGL_compressed_texture_s3tc" title="WebGL/Using_Extensions#WEBGL_compressed_texture_s3tc"><code>WEBGL_compressed_texture_s3tc</code></a></td>
        <td>{{CompatGeckoDesktop("15.0")}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><code>drawingBufferWidth</code> and <code>drawingBufferHeight</code> attributes</td>
        <td>{{CompatGeckoDesktop("9.0")}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>Chrome for Android</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>4</td>
        <td>25 (experiment)</td>
        <td>{{CompatNo}}</td>
        <td>12</td>
        <td>{{CompatNo}}</td>
      </tr>
      <tr>
        <td>Context name</td>
        <td><span style="color: rgb(34, 34, 34); font-family: 'courier new', monospace; font-size: 13px; line-height: normal; white-space: pre-wrap;">experimental-webgl</span></td>
        <td><span style="color: rgb(34, 34, 34); font-family: 'courier new', monospace; font-size: 12.666666984558105px; line-height: normal; white-space: pre-wrap;">experimental-webgl</span></td>
        <td>{{CompatNo}}</td>
        <td><span style="color: rgb(34, 34, 34); font-family: 'courier new', monospace; font-size: 13px; line-height: normal; white-space: pre-wrap;">experimental-webgl</span></td>
        <td>{{CompatNo}}</td>
      </tr>
      <tr>
        <td><code>drawingBufferWidth</code>&nbsp;and&nbsp;<code>drawingBufferHeight</code>&nbsp;attributes</td>
        <td>{{CompatGeckoMobile("9.0")}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt" title="http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt"><code>OES_texture_float</code></a></td>
        <td>{{CompatGeckoMobile("6.0")}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="http://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/" title="http://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/"><code>OES_standard_derivatives</code></a></td>
        <td>{{CompatGeckoMobile("10.0")}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="/en-US/docs/WebGL/Using_Extensions#EXT_texture_filter_anisotropic" title="WebGL/Using_Extensions#EXT_texture_filter_anisotropic"><code>EXT_texture_filter_anisotropic</code></a></td>
        <td>{{CompatGeckoMobile("13.0")}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><code>OES_element_index_uint</code></td>
        <td>{{CompatUnknown}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><code>OES_vertex_array_object</code></td>
        <td>{{CompatUnknown}}</td>
        <td>25</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><a href="/en-US/docs/WebGL/Using_Extensions#WEBGL_compressed_texture_s3tc" title="WebGL/Using_Extensions#WEBGL_compressed_texture_s3tc"><code>WEBGL_compressed_texture_s3tc</code></a></td>
        <td>{{CompatGeckoMobile("15.0")}}</td>
        <td>25<br />
          prefixed with&nbsp;<span style="color: rgb(34, 34, 34); font-family: 'courier new', monospace; font-size: 12.666666984558105px; line-height: normal; white-space: pre-wrap;">WEBKIT_</span></td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><code>WEBKIT_EXT_texture_filter_nisotropic</code></td>
        <td>{{CompatNo}}</td>
        <td>25</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h3 id="Compatibility_notes">Compatibility notes</h3>
<p>In addition to the browser, the GPU itself also needs to support the feature. So, for example, S3 Texture Compression (S3TC) is only available on Tegra-based tablets.</p>
<h3 id="Gecko_notes">Gecko notes</h3>
<h4 id="WebGL_debugging_and_testing">WebGL debugging and testing</h4>
<p>Starting with Gecko 10.0 {{geckoRelease("10.0")}}, there are two preferences available which let you control the capabilities of WebGL for testing purposes:</p>
<dl>
  <dt><code>webgl.min_capability_mode</code></dt>
  <dd>A Boolean property that, when <code>true</code>, enables a minimum capability mode. When in this mode, WebGL is configured to only support the bare minimum feature set and capabilities required by the WebGL specification. This lets you ensure that your WebGL code will work on any device or browser, regardless of their capabilities. This is <code>false</code> by default.</dd>
  <dt><code>webgl.disable_extensions</code></dt>
  <dd>A Boolean property that, when <code>true</code>, disables all WebGL extensions. This is <code>false</code> by default.</dd>
</dl>
<div>{{HTML5ArticleTOC}}</div>
Revert to this revision