I have a cube that is defined as:
float vertices[] = { -width, -height, -depth,
width, -height, -depth,
width, height, -depth,
-width, height, -depth,
-width, -height, depth,
width, -height, depth,
width, height, depth,
-width, height, depth
};
and I have a 128x128 image that I just want to draw on each of the 6 faces of the cube and nothing else. So what is the texture of cooridinates? I need actual values.
This is the drawing code:
gl.glFrontFace(GL10.GL_CCW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVerticesBuffer);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
gl.glColor4f(red, green, blue, alpha);
gl.glDrawElements(GL10.GL_TRIANGLES, mNumOfIndices,
GL10.GL_UNSIGNED_SHORT, mIndicesBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
This is an array of indices:
short indices[] = { 0, 2, 1,
0, 3, 2,
1,2,6,
6,5,1,
4,5,6,
6,7,4,
2,3,6,
6,3,7,
0,7,3,
0,4,7,
0,1,5,
0,5,4
};
I'm not sure if an index array is needed to find the tex coordinates. Note that the vertex array of the cube I gave is the most efficient representation of the cube using an array of indices. The cube draws fine, but not texture. Only one side shows the correct picture, but the other sides are corrupted. I used the methods described in various online textbooks on textures, but it does not work.