04-lighting/scripts/demo04-02.js
/**
 * Display function, sets up various matrices, binds data to the GPU,
 * and displays it.
 */
Display function, sets up various matrices, binds data to the GPU,
and displays it.
Display function sets up various matrices binds data to the GPU and displays it .
function draw() {
    gl.clear( gl.COLOR_BUFFER_BIT );
    mat4.identity( mvmat );
    mat4.rotateY( mvmat, yrot, mvmat );
    mat4.rotateX( mvmat, 0.25, mvmat );
    yrot += 0.01;
    if ( yrot >= 2 * Math.PI  ) {
        yrot -= 2 * Math.PI;
    }
    mat4.toInverseMat3( mvmat, nmat );
    mat3.transpose( nmat );
    gl.useProgram(gl_program);
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D, textures[0]);
    gl.uniform1i(gl_program_loc.uSampler, 0);
    gl.uniformMatrix4fv( gl_program_loc.uMVmat, false, mvmat );
    gl.uniformMatrix3fv( gl_program_loc.uNmat,  false, nmat );
    gl.activeTexture(gl.TEXTURE1);;
    gl.bindTexture(gl.TEXTURE_2D, textures[1]);
    gl.uniform1i(gl_program_loc.uNormalMap, 1);
    gl.uniform1i(gl_program_loc.uDrawState, drawState);
    gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
    gl.enableVertexAttribArray(gl_program_loc.aPosition);
    gl.enableVertexAttribArray(gl_program_loc.aTexCoord);
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices);
    gl.vertexAttribPointer(gl_program_loc.aPosition, 3, gl.FLOAT, false, 20,  0);
    gl.vertexAttribPointer(gl_program_loc.aTexCoord, 2, gl.FLOAT, false, 20, 12);
    gl.drawElements(gl.TRIANGLE_STRIP, 39, gl.UNSIGNED_SHORT, 0);
}
function draw ( ) { gl . clear ( gl . COLOR_BUFFER_BIT ) ; mat4 . identity ( mvmat ) ; mat4 . rotateY ( mvmat , yrot , mvmat ) ; mat4 . rotateX ( mvmat , 0.25 , mvmat ) ; yrot += 0.01 ; if ( yrot >= 2 * Math . PI ) { yrot -= 2 * Math . PI ; } mat4 . toInverseMat3 ( mvmat , nmat ) ; mat3 . transpose ( nmat ) ; gl . useProgram ( gl_program ) ; gl . activeTexture ( gl . TEXTURE0 ) ; gl . bindTexture ( gl . TEXTURE_2D , textures [ 0 ] ) ; gl . uniform1i ( gl_program_loc . uSampler , 0 ) ; gl . uniformMatrix4fv ( gl_program_loc . uMVmat , false , mvmat ) ; gl . uniformMatrix3fv ( gl_program_loc . uNmat , false , nmat ) ; gl . activeTexture ( gl . TEXTURE1 ) ; ; gl . bindTexture ( gl . TEXTURE_2D , textures [ 1 ] ) ; gl . uniform1i ( gl_program_loc . uNormalMap , 1 ) ; gl . uniform1i ( gl_program_loc . uDrawState , drawState ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , vbo ) ; gl . enableVertexAttribArray ( gl_program_loc . aPosition ) ; gl . enableVertexAttribArray ( gl_program_loc . aTexCoord ) ; gl . bindBuffer ( gl . ELEMENT_ARRAY_BUFFER , indices ) ; gl . vertexAttribPointer ( gl_program_loc . aPosition , 3 , gl . FLOAT , false , 20 , 0 ) ; gl . vertexAttribPointer ( gl_program_loc . aTexCoord , 2 , gl . FLOAT , false , 20 , 12 ) ; gl . drawElements ( gl . TRIANGLE_STRIP , 39 , gl . UNSIGNED_SHORT , 0 ) ; }
Display function, sets up various matrices, binds data to the GPU,
 and displays it.
Display function sets up various matrices binds data to the GPU and displays it .
// Clear the color buffer // Set mvmat to the proper rotation // Tilt the box slightly so all faces are visible during rotation // Use the created shader program // Set texture0 to have the stone texture // Set uSampler to have the value 0, so it uses TEXTURE0 // Send color uniform to the shader: // Set texture1 to have the normal map // Set uNormalMap to have the value 1, so it uses TEXTURE1 // Send the drawstate to the shader // Bind vbo to be the current array buffer // Enables a vertex attribute array for vertex positions // Setup the pointer to the position data