1.1 --- a/scripts/renderer.js Fri Apr 29 17:10:15 2011 +0200
1.2 +++ b/scripts/renderer.js Sat Apr 30 04:05:47 2011 +0200
1.3 @@ -65,11 +65,16 @@
1.4 this.vertexColour = gl.getAttribLocation(this.program, "aVertexColour");
1.5 gl.enableVertexAttribArray(this.vertexColour);
1.6
1.7 + this.textureCoord = gl.getAttribLocation(this.program, "aTextureCoord");
1.8 + gl.enableVertexAttribArray(this.textureCoord);
1.9 +
1.10 this.pMatrixUniform = gl.getUniformLocation(this.program, "uPMatrix");
1.11 this.mvMatrixUniform = gl.getUniformLocation(this.program, "uMVMatrix");
1.12 this.nMatrixUniform = gl.getUniformLocation(this.program, "uNMatrix");
1.13 + this.samplerUniform = gl.getUniformLocation(this.program, "uSampler");
1.14 this.materialShininessUniform = gl.getUniformLocation(this.program, "uMaterialShininess");
1.15 this.useLightingUniform = gl.getUniformLocation(this.program, "uUseLighting");
1.16 + this.useTexture = gl.getUniformLocation(this.program, "uUseTexture");
1.17 this.ambientColourUniform = gl.getUniformLocation(this.program, "uAmbientColour");
1.18 this.lightingDirectionUniform = gl.getUniformLocation(this.program, "uLightingDirection");
1.19 this.directionalColourUniform = gl.getUniformLocation(this.program, "uDirectionalColour");
1.20 @@ -185,6 +190,21 @@
1.21 gl.bindBuffer(gl.ARRAY_BUFFER, object.normalBuffer);
1.22 gl.vertexAttribPointer(shader.vertexNormal, object.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);
1.23
1.24 + gl.bindBuffer(gl.ARRAY_BUFFER, object.textureCoordBuffer);
1.25 + gl.vertexAttribPointer(shader.textureCoord, object.textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
1.26 + gl.activeTexture(gl.TEXTURE0);
1.27 + if (object.texture && object.useTexture)
1.28 + {
1.29 + gl.uniform1i(shader.useTexture, true);
1.30 +
1.31 + gl.bindTexture(gl.TEXTURE_2D, object.texture.hnd);
1.32 + gl.uniform1i(shader.samplerUniform, 0);
1.33 + }
1.34 + else
1.35 + {
1.36 + gl.uniform1i(shader.useTexture, false);
1.37 +
1.38 + }
1.39 gl.bindBuffer(gl.ARRAY_BUFFER, object.colourBuffer);
1.40 gl.vertexAttribPointer(shader.vertexColour, object.colourBuffer.itemSize, gl.FLOAT, false, 0, 0);
1.41