06-fun/scripts/06-02-modelloader.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 display() {
    gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );
    quat4.toMat4( controller.currentOrientation, mvmat );
    mat4.toInverseMat3( mvmat, nmat );
    mat3.transpose( nmat );
    gl.useProgram(gl_program);
    gl.uniformMatrix4fv(gl_program_loc.uPMatrix,  false, projmat);
    gl.uniformMatrix4fv(gl_program_loc.uMVMatrix, false, mvmat);
    gl.uniformMatrix3fv(gl_program_loc.uNMatrix,  false, nmat);
    gl.uniform3fv(gl_program_loc.uColor, new Float32Array([0.5, 0.5, 0.5]));
    gl.uniform1i(gl_program_loc.uLighting, lighting ? 1 : 0 );
    if( vbo.length > 0 ) {
        gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
        gl.enableVertexAttribArray(gl_program_loc.aPosition);
        gl.vertexAttribPointer(gl_program_loc.aPosition, 3, gl.FLOAT, false, 12,  0);
        if( line ) {
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, lineIndices);
            gl.drawElements(gl.LINE_LOOP, lineIndices.length, gl.UNSIGNED_SHORT, 0);
        } else {
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, triIndices);
            gl.drawElements(gl.TRIANGLES, triIndices.length, gl.UNSIGNED_SHORT, 0);
        }
    }
}
function display ( ) { gl . clear ( gl . COLOR_BUFFER_BIT | gl . DEPTH_BUFFER_BIT ) ; quat4 . toMat4 ( controller . currentOrientation , mvmat ) ; mat4 . toInverseMat3 ( mvmat , nmat ) ; mat3 . transpose ( nmat ) ; gl . useProgram ( gl_program ) ; gl . uniformMatrix4fv ( gl_program_loc . uPMatrix , false , projmat ) ; gl . uniformMatrix4fv ( gl_program_loc . uMVMatrix , false , mvmat ) ; gl . uniformMatrix3fv ( gl_program_loc . uNMatrix , false , nmat ) ; gl . uniform3fv ( gl_program_loc . uColor , new Float32Array ( [ 0.5 , 0.5 , 0.5 ] ) ) ; gl . uniform1i ( gl_program_loc . uLighting , lighting ? 1 : 0 ) ; if ( vbo . length > 0 ) { gl . bindBuffer ( gl . ARRAY_BUFFER , vbo ) ; gl . enableVertexAttribArray ( gl_program_loc . aPosition ) ; gl . vertexAttribPointer ( gl_program_loc . aPosition , 3 , gl . FLOAT , false , 12 , 0 ) ; if ( line ) { gl . bindBuffer ( gl . ELEMENT_ARRAY_BUFFER , lineIndices ) ; gl . drawElements ( gl . LINE_LOOP , lineIndices . length , gl . UNSIGNED_SHORT , 0 ) ; } else { gl . bindBuffer ( gl . ELEMENT_ARRAY_BUFFER , triIndices ) ; gl . drawElements ( gl . TRIANGLES , triIndices . length , 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 the model-view matrix to the current CameraController rotation // Get the normal matrix from the model-view matrix (for lighting) // Use the created shader program // Upload the projection matrix and the model-view matrix to the shader // If there is a model loaded // Bind vbo to be the current array buffer // Enables a vertex attribute array for vertex positions // Setup the pointer to the position data // Bind lineIndices to be the current index array buffer // Finally, draw the data as lines using all of the current settings