WebGL Textures & Vertices

Beginner's Guide

Page Seventy Eight

Finalize & Display the Mesh

The GLEntity method setImage(EventObject ev) tracks the number of image's downloaded. For every image loaded, increment the controller's nImagesLoaded property. The following line demonstrates tracking the number of images downloaded.

controller.nImagesLoaded++;

When every image has loaded, then finalize the program and show the first frame of the animation. GLEntity calls the controller's method setProgramVariables(), after all images have downloaded.

if (controller.nImagesToLoad 
    <= 
    controller.nImagesLoaded
)
{   
 controller.setProgramVariables(
  controller
 );  
}

Listing 78: Call setProgramVariables(controller)

The method setProgramVariables(controller) part of the GLControl class, finalizes values for the WebGLProgram and draws one frame of the scene. The last statement in setProgramVariables(controller) calls animOne(ev). Method animOne(ev) displays one frame of the animation.

setProgramVariables(controller) calls three WebGL methods. First verify the program functionality with a call to validateProgram(WebGLProgram). If the WebGLProgram doesn't validate, then call WebGL methods getProgramParameter(WebGLProgram, Number), getProgramInfoLog(WebGLProgram), and deleteProgram(WebGLProgram). For invalid programs terminate processing. Otherwise the controller renders a frame to the canvas.

WebGL Beginner's Guide Introduction WebGL Beginner's Guide
Copyright © 2015 Seven Thunder Software. All Rights Reserved.