October 2018
Intermediate to advanced
500 pages
12h 40m
English
Once we have compiled and installed the program, the next step is to initialize the attributes and variables. We will initialize our uniforms using the initLights function:
function initLights() { gl.uniform3fv(program.uLightDirection, [0, 0, -1]); gl.uniform4fv(program.uLightAmbient, [0.01, 0.01, 0.01, 1]); gl.uniform4fv(program.uLightDiffuse, [0.5, 0.5, 0.5, 1]); gl.uniform4f(program.uMaterialDiffuse, 0.1, 0.5, 0.8, 1);}
In this example, you can see that we’re using the references obtained with getUniformLocation (we did this in initProgram).
These are the functions that the WebGL API provides to set and get uniform values:
| WebGL Function | Description |
| uniform[1234][fi] | Specifies 1-4 float or int ... |