function initShaders() {
        var fragmentShader = compileShader(fragmentShaderCode, 'fragment');
        var vertexShader = compileShader(vertexShaderCode, 'vertex');
        var shaderProgram = gl.createProgram();

        gl.attachShader(shaderProgram, vertexShader);
        gl.attachShader(shaderProgram, fragmentShader);
        gl.linkProgram(shaderProgram);

        if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
            alert('Could not initialise shaders');
        }
        
        gl.useProgram(shaderProgram);
        shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, 'aVertexPosition');
        gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
        shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, 'aVertexNormal');
        gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute);
        shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, 'aTextureCoord');
        gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);

        var jsVariableShaderVariablePairs = {
            'pMatrixUniform':                    'uPMatrix',
            'mvMatrixUniform':                   'uMVMatrix',
            'nMatrixUniform':                    'uNMatrix',
            'samplerUniform':                    'uSampler',
            'showSpecularSamplerUniform':        'uShowSpecularSampler',
            'specularSamplerUniform':            'uSpecularSampler',
            'materialShininessUniform':          'uMaterialShininess',
            'showSpecularHighlightsUniform':     'uShowSpecularHighlights',
            'useTexturesUniform':                'uUseTextures',
            'useLightingUniform':                'uUseLighting',
            'ambientColorUniform':               'uAmbientColor',
            'pointLightingLocationUniform':      'uPointLightingLocation',
            'pointLightingSpecularColorUniform': 'uPointLightingSpecularColor',
            'pointLightingDiffuseColorUniform':  'uPointLightingDiffuseColor',
            'alphaUniform':                      'uAlpha'
        }

        for (var jsVariable in jsVariableShaderVariablePairs) {
            var shaderVariable = jsVariableShaderVariablePairs[jsVariable];
            shaderProgram[jsVariable] = gl.getUniformLocation(shaderProgram, shaderVariable);
        }

        return shaderProgram;
    }
/**
     * Initialises the shaders.
     * @class Shaders
     * @constructor
     * @return {Object} The shader program containing the compiled shaders.
     */
Initialises the shaders.
@class Shaders
@constructor
@return {Object} The shader program containing the compiled shaders.
Initialises the shaders . @class Shaders @constructor @return { Object } The shader program containing the compiled shaders .
function initShaders() {
        var fragmentShader = compileShader(fragmentShaderCode, 'fragment');
        var vertexShader = compileShader(vertexShaderCode, 'vertex');
        var shaderProgram = gl.createProgram();
        gl.attachShader(shaderProgram, vertexShader);
        gl.attachShader(shaderProgram, fragmentShader);
        gl.linkProgram(shaderProgram);
        if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
            alert('Could not initialise shaders');
        }
        gl.useProgram(shaderProgram);
        shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, 'aVertexPosition');
        gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
        shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, 'aVertexNormal');
        gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute);
        shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, 'aTextureCoord');
        gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
        var jsVariableShaderVariablePairs = {
            'pMatrixUniform':                    'uPMatrix',
            'mvMatrixUniform':                   'uMVMatrix',
            'nMatrixUniform':                    'uNMatrix',
            'samplerUniform':                    'uSampler',
            'showSpecularSamplerUniform':        'uShowSpecularSampler',
            'specularSamplerUniform':            'uSpecularSampler',
            'materialShininessUniform':          'uMaterialShininess',
            'showSpecularHighlightsUniform':     'uShowSpecularHighlights',
            'useTexturesUniform':                'uUseTextures',
            'useLightingUniform':                'uUseLighting',
            'ambientColorUniform':               'uAmbientColor',
            'pointLightingLocationUniform':      'uPointLightingLocation',
            'pointLightingSpecularColorUniform': 'uPointLightingSpecularColor',
            'pointLightingDiffuseColorUniform':  'uPointLightingDiffuseColor',
            'alphaUniform':                      'uAlpha'
        }
        for (var jsVariable in jsVariableShaderVariablePairs) {
            var shaderVariable = jsVariableShaderVariablePairs[jsVariable];
            shaderProgram[jsVariable] = gl.getUniformLocation(shaderProgram, shaderVariable);
        }
        return shaderProgram;
    }
function initShaders ( ) { var fragmentShader = compileShader ( fragmentShaderCode , 'fragment' ) ; var vertexShader = compileShader ( vertexShaderCode , 'vertex' ) ; var shaderProgram = gl . createProgram ( ) ; gl . attachShader ( shaderProgram , vertexShader ) ; gl . attachShader ( shaderProgram , fragmentShader ) ; gl . linkProgram ( shaderProgram ) ; if ( ! gl . getProgramParameter ( shaderProgram , gl . LINK_STATUS ) ) { alert ( 'Could not initialise shaders' ) ; } gl . useProgram ( shaderProgram ) ; shaderProgram . vertexPositionAttribute = gl . getAttribLocation ( shaderProgram , 'aVertexPosition' ) ; gl . enableVertexAttribArray ( shaderProgram . vertexPositionAttribute ) ; shaderProgram . vertexNormalAttribute = gl . getAttribLocation ( shaderProgram , 'aVertexNormal' ) ; gl . enableVertexAttribArray ( shaderProgram . vertexNormalAttribute ) ; shaderProgram . textureCoordAttribute = gl . getAttribLocation ( shaderProgram , 'aTextureCoord' ) ; gl . enableVertexAttribArray ( shaderProgram . textureCoordAttribute ) ; var jsVariableShaderVariablePairs = { 'pMatrixUniform' : 'uPMatrix' , 'mvMatrixUniform' : 'uMVMatrix' , 'nMatrixUniform' : 'uNMatrix' , 'samplerUniform' : 'uSampler' , 'showSpecularSamplerUniform' : 'uShowSpecularSampler' , 'specularSamplerUniform' : 'uSpecularSampler' , 'materialShininessUniform' : 'uMaterialShininess' , 'showSpecularHighlightsUniform' : 'uShowSpecularHighlights' , 'useTexturesUniform' : 'uUseTextures' , 'useLightingUniform' : 'uUseLighting' , 'ambientColorUniform' : 'uAmbientColor' , 'pointLightingLocationUniform' : 'uPointLightingLocation' , 'pointLightingSpecularColorUniform' : 'uPointLightingSpecularColor' , 'pointLightingDiffuseColorUniform' : 'uPointLightingDiffuseColor' , 'alphaUniform' : 'uAlpha' } for ( var jsVariable in jsVariableShaderVariablePairs ) { var shaderVariable = jsVariableShaderVariablePairs [ jsVariable ] ; shaderProgram [ jsVariable ] = gl . getUniformLocation ( shaderProgram , shaderVariable ) ; } return shaderProgram ; }
Initialises the shaders.
Initialises the shaders .