03-3dimensions/scripts/demo03-05.js
/**
 * Initializes the shaders used for the program
 */
Initializes the shaders used for the program
Initializes the shaders used for the program
function initShaders() {
    var vertexShader   = loadShader(   gl.VERTEX_SHADER, document.getElementById('vshader').innerHTML );
    var fragmentShader = loadShader( gl.FRAGMENT_SHADER, document.getElementById('fshader').innerHTML );
    var programObject = gl.createProgram();
    gl.attachShader(programObject, vertexShader);
    gl.attachShader(programObject, fragmentShader);
    gl_program = programObject;
    gl.linkProgram(gl_program);
    var linked = gl.getProgramParameter(gl_program, gl.LINK_STATUS);
    if( !linked && !gl.isContextLost()) {
        var infoLog = gl.getProgramInfoLog(gl_program);
        window.console.log("Error linking program:\n" + infoLog);
        gl.deleteProgram(gl_program);
        return;
    }
    gl_program_loc.aPosition = gl.getAttribLocation(gl_program, "aPosition");
    gl_program_loc.aTexCoord = gl.getAttribLocation(gl_program, "aTexCoord");
    gl_program_loc.uMVmat = gl.getUniformLocation(gl_program, "uMVmat");
    gl_program_loc.uSampler = gl.getUniformLocation(gl_program, "uSampler");
}
function initShaders ( ) { var vertexShader = loadShader ( gl . VERTEX_SHADER , document . getElementById ( 'vshader' ) . innerHTML ) ; var fragmentShader = loadShader ( gl . FRAGMENT_SHADER , document . getElementById ( 'fshader' ) . innerHTML ) ; var programObject = gl . createProgram ( ) ; gl . attachShader ( programObject , vertexShader ) ; gl . attachShader ( programObject , fragmentShader ) ; gl_program = programObject ; gl . linkProgram ( gl_program ) ; var linked = gl . getProgramParameter ( gl_program , gl . LINK_STATUS ) ; if ( ! linked && ! gl . isContextLost ( ) ) { var infoLog = gl . getProgramInfoLog ( gl_program ) ; window . console . log ( "Error linking program:\n" + infoLog ) ; gl . deleteProgram ( gl_program ) ; return ; } gl_program_loc . aPosition = gl . getAttribLocation ( gl_program , "aPosition" ) ; gl_program_loc . aTexCoord = gl . getAttribLocation ( gl_program , "aTexCoord" ) ; gl_program_loc . uMVmat = gl . getUniformLocation ( gl_program , "uMVmat" ) ; gl_program_loc . uSampler = gl . getUniformLocation ( gl_program , "uSampler" ) ; }
Initializes the shaders used for the program
Initializes the shaders used for the program
// Load the shaders and compile them (shaders are located in the HTML) // Create the program object // link the program // verify link // Get the uniform/attribute locations