Game Development Reference
In-Depth Information
function setMatrixUniforms(i) {
gl.uniformMatrix4fv(shaderPrograms[i].pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderPrograms[i].mvMatrixUniform, false, mvMatrix);
}
function getVertexAttributes(i){
vertexPositionAttributes[i] = gl.getAttribLocation(shaderPrograms[i],
"aVertexPosition");
gl.enableVertexAttribArray(vertexPositionAttributes[i]);
if(i == TEXTURE_SHADER){
textureCoordAttributes[i] = gl.getAttribLocation(shaderPrograms[i],
"aTextureCoord");
gl.enableVertexAttribArray(textureCoordAttributes[i]);
}else if(i == COLOR_SHADER){
vertexColorAttributes[i] = gl.getAttribLocation(shaderPrograms[i],
"aVertexColor");
gl.enableVertexAttribArray(vertexColorAttributes[i]);
}
}
function executeProgram(){
for(var i=0;i<NUM_SHADERS; ++i){
getMatrixUniforms(i);
getVertexAttributes(i);
}
initBuffers();
(function animLoop(){
drawScene();
requestAnimFrame(animLoop, canvas);
})();
}
In Listing 7-27, we refactor our initBuffers and drawScene methods to call the octahedron (dart) and
dartboard method calls.
Listing 7-27. Drawing Our Scene and the Dartboard
function initBuffers() {
initOctahedronBuffer();
initDartboardBuffer();
}
function drawScene() {
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0,
pMatrix);
drawDartboard();
drawDart();
 
Search WWH ::




Custom Search