Create a Usable Program

 60                 // Create a program from the shaders
 61                 function createProgram(gl, vertexShader, fragmentShader)
 62                 {
 63                     var program = gl.createProgram();
 64                     // The program consists of our shaders
 65                     gl.attachShader(program, vertexShader);
 66                     gl.attachShader(program, fragmentShader);
 67 
 68                     // Create a runnable program for our graphics hardware.
 69                     // Allocates and assigns memory for attributes and uniforms (explained later)
 70                     // Shaders are checked for consistency.
 71                     gl.linkProgram(program);
 72 
 73                     if (!gl.getProgramParameter(program, gl.LINK_STATUS))
 74                     {
 75                         alert("Could not link program: " + gl.getProgramInfoLog (program));
 76                     }
 77 
 78 
 79 
 80                     return program;
 81                 }
(0,1) (-1,-1) (1,-1)

Notes

OK, we've already compiled the shaders. And now, just as you might link and load separately compiled C modules into a program, we load and link the shaders into a runnable program. The first step in the process, gl.createProgram() creates an empty program, and returns a integer reference to the program. This refeence will be zero if the creation operation fails.

The reference to the program is used along with similar references to the shaders to define the required vertex and fragment shaders in the program.

Once again we make an explicit check on the status of the operation, and retrieve the log when appropriate.