diff --git a/lib/game2.js b/lib/game2.js index 1685996..a720288 100644 --- a/lib/game2.js +++ b/lib/game2.js @@ -145,8 +145,18 @@ 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); @@ -154,7 +164,11 @@ function drawScene() { 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); @@ -174,10 +188,6 @@ function drawScene() { setMatrixUniforms(); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); - - - - Platform.flip(); } @@ -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; + } } } @@ -214,6 +231,11 @@ function animate() { drawScene(); drawSprite(); + gl.flush(); + var err = gl.getError(); + if (err) { + console.log("GOT GL ERROR: " + err); + } }