O'Reilly logo

WebGL Beginner's Guide by Brandon Jones, Diego Cantor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — setting up WebGL context attributes

In this example, we are going to learn to modify the color that we use to clear the canvas:

  1. Using your favorite text editor, open the file ch1_GL_Attributes.html:
    <html> <head> <title> WebGL Beginner's Guide - Setting WebGL context attributes </title> <style type="text/css"> canvas {border: 2px dotted blue;} </style> <script> var gl = null; var c_width = 0; var c_height = 0; window.onkeydown = checkKey; function checkKey(ev){ switch(ev.keyCode){ case 49:{ // 1 gl.clearColor(0.3,0.7,0.2,1.0); clear(gl); break; } case 50:{ // 2 gl.clearColor(0.3,0.2,0.7,1.0); clear(gl); break; } case 51:{ // 3 var color = gl.getParameter(gl.COLOR_CLEAR_VALUE); // Don't get confused with the following line. It ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required