scripts/cube.js
changeset 36 a828c4cde5b3
parent 35 7769f6e1e2c5
     1.1 --- a/scripts/cube.js	Fri Apr 29 17:10:15 2011 +0200
     1.2 +++ b/scripts/cube.js	Sat Apr 30 04:05:47 2011 +0200
     1.3 @@ -20,9 +20,11 @@
     1.4      for (var id in this.children) this.children[id].update(time);
     1.5  }
     1.6  
     1.7 -function CubeVbo(size, context)
     1.8 +function CubeVbo(size, context, texture)
     1.9  {
    1.10      var gl = context.gl;
    1.11 +    this.texture = texture;
    1.12 +    this.useTexture = texture;
    1.13      this.size = size || 1;    
    1.14      this.positionBuffer = gl.createBuffer();
    1.15      gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
    1.16 @@ -102,6 +104,45 @@
    1.17      this.normalBuffer.itemSize = 3;
    1.18      this.normalBuffer.numItems = 24;
    1.19  
    1.20 +    //if (this.texture)
    1.21 +    //{
    1.22 +	this.textureCoordBuffer = gl.createBuffer();
    1.23 +	gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
    1.24 +	var textureCoords = [// front face
    1.25 +	    0.0, 0.0,
    1.26 +	    1.0, 0.0,
    1.27 +	    1.0, 1.0,
    1.28 +	    0.0, 1.0,
    1.29 +	    //back face
    1.30 +	    1.0, 0.0,
    1.31 +	    1.0, 1.0,
    1.32 +	    0.0, 1.0,
    1.33 +	    0.0, 0.0,
    1.34 +	    // top face
    1.35 +	    0.0, 1.0,
    1.36 +	    0.0, 0.0,
    1.37 +	    1.0, 0.0,
    1.38 +	    1.0, 1.0,
    1.39 +	    // bottom face
    1.40 +	    1.0, 1.0,
    1.41 +	    0.0, 1.0,
    1.42 +	    0.0, 0.0,
    1.43 +	    1.0, 0.0,
    1.44 +	    // right face
    1.45 +	    1.0, 0.0, 
    1.46 +	    1.0, 1.0,
    1.47 +	    0.0, 1.0,
    1.48 +	    0.0, 0.0,
    1.49 +	    // left face
    1.50 +	    0.0, 0.0,
    1.51 +	    1.0, 0.0,
    1.52 +	    1.0, 1.0,
    1.53 +	    0.0, 1.0];
    1.54 +	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);
    1.55 +	this.textureCoordBuffer.itemSize = 2;
    1.56 +	this.textureCoordBuffer.numItems = 24;
    1.57 +    //}
    1.58 +   
    1.59      this.colourBuffer = gl.createBuffer();
    1.60      gl.bindBuffer(gl.ARRAY_BUFFER, this.colourBuffer);
    1.61      var alpha = 1.0;
    1.62 @@ -125,7 +166,7 @@
    1.63      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(unpackedColours), gl.STATIC_DRAW);
    1.64      this.colourBuffer.itemSize = 4;
    1.65      this.colourBuffer.numItems = 24;
    1.66 -
    1.67 +    
    1.68      this.indexBuffer = gl.createBuffer();
    1.69      gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
    1.70      var indices = [0, 1, 2, 0, 2, 3,