Game Development Reference
In-Depth Information
$.ajax({
async: false,
url: 'shader.vs',
success: function (data) {
vertexShaderSRC = data.firstChild.textContent;
},
dataType: 'xml'
});
setupShaders(fragmentShaderSRC, vertexShaderSRC);
}
function getMatrixUniforms(){
shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram,
"uPMatrix");
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram,
"uMVMatrix");
}
function setMatrixUniforms() {
gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
}
function getVertexAttributes(){
vertexPositionAttribute = gl.getAttribLocation(shaderProgram,
"aVertexPosition");
gl.enableVertexAttribArray(vertexPositionAttribute);
vertexColorAttribute = gl.getAttribLocation(shaderProgram,
"aVertexColor");
gl.enableVertexAttribArray(vertexColorAttribute);
}
function executeProgram(){
getMatrixUniforms();
getVertexAttributes();
initBuffers();
drawScene();
}
function drawScene() {
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT);
mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0,
pMatrix);
mat4.identity(mvMatrix);
mat4.translate(mvMatrix, [0, 0.0, -7.0]);
setMatrixUniforms();
gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesBuffer);
Search WWH ::




Custom Search