05-input/scripts/demo05-02.js
/**
 * Initializes all variables, shaders, and WebGL options 
 * needed for this program.
 */
Initializes all variables, shaders, and WebGL options
needed for this program.
Initializes all variables shaders and WebGL options needed for this program .
function init() {
    gl.clearColor(1.0, 1.0, 1.0, 1.0);
    vbo = gl.createBuffer();
    indices = gl.createBuffer();
    mvmat = mat4.create();
    nmat = mat3.create();
    controller = new CameraController(document.getElementById("c"));
    controller.onchange = draw();
    loadTextures();
    gl.enable( gl.CULL_FACE );
    gl.frontFace( gl.CCW );
    gl.cullFace( gl.BACK );
    gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
    gl.depthRange( 10.0, 10.0 );
    var vertices = new Float32Array([ -0.5, -0.5,  0.5, 0.0, 0.0, 
                                       0.5, -0.5,  0.5, 1.0, 0.0, 
                                      -0.5,  0.5,  0.5, 0.0, 1.0,
                                       0.5,  0.5,  0.5, 1.0, 1.0,
                                       0.5, -0.5, -0.5, 1.0, -0.25,                                       
                                       0.5, -0.5,  0.5, 0.0, -0.25,
                                       0.5,  0.5, -0.5, 1.0,  0.75,
                                       0.5,  0.5,  0.5, 0.0,  0.75,
                                       0.5, -0.5, -0.5, 0.0, 0.0,                                      
                                      -0.5, -0.5, -0.5, 1.0, 0.0,
                                       0.5,  0.5, -0.5, 0.0, 1.0,
                                      -0.5,  0.5, -0.5, 1.0, 1.0,
                                      -0.5, -0.5,  0.5, 1.0, -0.25,
                                      -0.5, -0.5, -0.5, 0.0, -0.25,
                                      -0.5,  0.5,  0.5, 1.0,  0.75,
                                      -0.5,  0.5, -0.5, 0.0,  0.75,
                                      -0.5, -0.5,  0.5, 0.0, 0.0,
                                      -0.5, -0.5, -0.5, 1.0, 0.0,
                                       0.5, -0.5,  0.5, 0.0, 1.0,
                                       0.5, -0.5, -0.5, 1.0, 1.0,
                                       0.5,  0.5,  0.5, 1.0, 0.0,
                                      -0.5,  0.5,  0.5, 0.0, 0.0,
                                       0.5,  0.5, -0.5, 1.0, 1.0,
                                      -0.5,  0.5, -0.5, 0.0, 1.0
                                   ]);
    gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 0, 1, 2, 3, 3, 3, 4,
                                                             4, 5, 6, 7, 7, 7, 8,
                                                             8, 9,10,11,11,11,12,
                                                            12,13,14,15,15,15,16,
                                                            16,17,18,19,19,19,20,
                                                            20,21,22,23]), gl.STATIC_DRAW);
    initShaders();
}
function init ( ) { gl . clearColor ( 1.0 , 1.0 , 1.0 , 1.0 ) ; vbo = gl . createBuffer ( ) ; indices = gl . createBuffer ( ) ; mvmat = mat4 . create ( ) ; nmat = mat3 . create ( ) ; controller = new CameraController ( document . getElementById ( "c" ) ) ; controller . onchange = draw ( ) ; loadTextures ( ) ; gl . enable ( gl . CULL_FACE ) ; gl . frontFace ( gl . CCW ) ; gl . cullFace ( gl . BACK ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , vbo ) ; gl . depthRange ( 10.0 , 10.0 ) ; var vertices = new Float32Array ( [ - 0.5 , - 0.5 , 0.5 , 0.0 , 0.0 , 0.5 , - 0.5 , 0.5 , 1.0 , 0.0 , - 0.5 , 0.5 , 0.5 , 0.0 , 1.0 , 0.5 , 0.5 , 0.5 , 1.0 , 1.0 , 0.5 , - 0.5 , - 0.5 , 1.0 , - 0.25 , 0.5 , - 0.5 , 0.5 , 0.0 , - 0.25 , 0.5 , 0.5 , - 0.5 , 1.0 , 0.75 , 0.5 , 0.5 , 0.5 , 0.0 , 0.75 , 0.5 , - 0.5 , - 0.5 , 0.0 , 0.0 , - 0.5 , - 0.5 , - 0.5 , 1.0 , 0.0 , 0.5 , 0.5 , - 0.5 , 0.0 , 1.0 , - 0.5 , 0.5 , - 0.5 , 1.0 , 1.0 , - 0.5 , - 0.5 , 0.5 , 1.0 , - 0.25 , - 0.5 , - 0.5 , - 0.5 , 0.0 , - 0.25 , - 0.5 , 0.5 , 0.5 , 1.0 , 0.75 , - 0.5 , 0.5 , - 0.5 , 0.0 , 0.75 , - 0.5 , - 0.5 , 0.5 , 0.0 , 0.0 , - 0.5 , - 0.5 , - 0.5 , 1.0 , 0.0 , 0.5 , - 0.5 , 0.5 , 0.0 , 1.0 , 0.5 , - 0.5 , - 0.5 , 1.0 , 1.0 , 0.5 , 0.5 , 0.5 , 1.0 , 0.0 , - 0.5 , 0.5 , 0.5 , 0.0 , 0.0 , 0.5 , 0.5 , - 0.5 , 1.0 , 1.0 , - 0.5 , 0.5 , - 0.5 , 0.0 , 1.0 ] ) ; gl . bufferData ( gl . ARRAY_BUFFER , vertices , gl . STATIC_DRAW ) ; gl . bindBuffer ( gl . ELEMENT_ARRAY_BUFFER , indices ) ; gl . bufferData ( gl . ELEMENT_ARRAY_BUFFER , new Uint16Array ( [ 0 , 1 , 2 , 3 , 3 , 3 , 4 , 4 , 5 , 6 , 7 , 7 , 7 , 8 , 8 , 9 , 10 , 11 , 11 , 11 , 12 , 12 , 13 , 14 , 15 , 15 , 15 , 16 , 16 , 17 , 18 , 19 , 19 , 19 , 20 , 20 , 21 , 22 , 23 ] ) , gl . STATIC_DRAW ) ; initShaders ( ) ; }
Initializes all variables, shaders, and WebGL options
 needed for this program.
Initializes all variables shaders and WebGL options needed for this program .
// Set the clear color to fully transparent black // Create the two buffer objects // Create the matrices // Initialize a new camera controller that draws the scene // on an update // Load the texture(s) // Cull the back face ( determined by counter clockwise winding ) // Bind the vertex buffer object // Put 24 vertices of a cube in the VBO // Bind and set the data of the lineIndices buffer // Initialize the shaders