Skip to content

Commit

Permalink
various improvements to game2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gargus committed Aug 27, 2011
1 parent b01e363 commit 840e2cf
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions lib/game2.js
Expand Up @@ -145,16 +145,30 @@ function initBuffers() {

}


var trans = 0;
function drawScene() {
gl.useProgram(shaderProgram);

vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray(vertexPositionAttribute);

vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray(vertexColorAttribute);



gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);

mat4.identity(mvMatrix);

mat4.translate(mvMatrix, [-1.5, 0.0, -7.0]);
var myTrans = Math.sin(trans);
trans += 0.01;
if (trans > 2*Math.PI) trans = 0;

mat4.translate(mvMatrix, [-1.5 + myTrans, 0.0, -7.0]);
gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0);

Expand All @@ -174,10 +188,6 @@ function drawScene() {
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);





Platform.flip();
}

Expand All @@ -191,7 +201,14 @@ Engine.loadSpriteMap(require('sprites/ship'), function(error, map) {

function drawSprite() {
if (sprite1) {
console.log("DRAWING SPRITE (well, not really)");
try {
sprite1.draw();
}
catch(e) {
console.log("ERROR DRAWING SPRITE: " + e);
sprite1 = null;
throw e;
}
}
}

Expand All @@ -214,6 +231,11 @@ function animate() {
drawScene();
drawSprite();

gl.flush();
var err = gl.getError();
if (err) {
console.log("GOT GL ERROR: " + err);
}
}


0 comments on commit 840e2cf

Please sign in to comment.