diff -r 7769f6e1e2c5 -r a828c4cde5b3 scripts/cube.js --- a/scripts/cube.js Fri Apr 29 17:10:15 2011 +0200 +++ b/scripts/cube.js Sat Apr 30 04:05:47 2011 +0200 @@ -20,9 +20,11 @@ for (var id in this.children) this.children[id].update(time); } -function CubeVbo(size, context) +function CubeVbo(size, context, texture) { var gl = context.gl; + this.texture = texture; + this.useTexture = texture; this.size = size || 1; this.positionBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer); @@ -102,6 +104,45 @@ this.normalBuffer.itemSize = 3; this.normalBuffer.numItems = 24; + //if (this.texture) + //{ + this.textureCoordBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer); + var textureCoords = [// front face + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + //back face + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + // top face + 0.0, 1.0, + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + // bottom face + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + 1.0, 0.0, + // right face + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + // left face + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0]; + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW); + this.textureCoordBuffer.itemSize = 2; + this.textureCoordBuffer.numItems = 24; + //} + this.colourBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, this.colourBuffer); var alpha = 1.0; @@ -125,7 +166,7 @@ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(unpackedColours), gl.STATIC_DRAW); this.colourBuffer.itemSize = 4; this.colourBuffer.numItems = 24; - + this.indexBuffer = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); var indices = [0, 1, 2, 0, 2, 3,