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 — texturing the cube

Open the file ch7_Textured_Cube.html in your favorite HTML editor. This contains the simple lit cube example from the previous chapter. If you open it in an HTML5 browser, you should see a scene that looks like the following screenshot:

Time for action — texturing the cube

In this example we will add a texture map to this cube as shown here:

  1. First, let's load the texture image. At the top of the script block, add a new variable to hold the texture:
    var texture = null;
    
  2. Then, at the bottom of the configure function, add the following code, which creates the texture object, loads an image, and sets the image as the texture data. In this case, we'll use ...

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