I’m a complete noob, but have had some success with the tutorials by Jeff LaMarche.
I am using Open GL ES 1.1 on the iPhone. What I’m trying to do is have different rendering of the same geometry display different sections of the same texture map.
To make this more concrete: I have an array of 5 X 7 tiles – much like Scrabble tiles. Each of the two main sides is supposed to display a letter. A texture map is divided into 64 areas, each with a letter.
I initialize and store 35 Cocoa objects that correspond to each tile. Each one has two objects that store information about the front and back face of the tile it represents. A randomizing routine guarantees that they are different from each other.
At run time, during rendering, I loop through two nested loops and retrieve the appropriate object and extract the coordinates it has calculated for the offset in the texture map. I push these into the appropriate slots in an Array called texCoords. This means that just before I call glDrawArrays, texCoords has the appropriate values in it that (as far as I can tell) ought to cause the corresponding section of the texture map to be drawn on the appropriate faces.
This is not what is happening. I initialize the texCoords array with values that will draw a certain letter on the faces of the tiles, and it is those initial values that are drawn. In other words, every tile has the same (initially set) letter on it, and it never changes.
Obviously, openGL needs to dump the old value that it is initially fed, and my code is not doing that. This is the core of the rendering process:
static GLfloat rot = 0.0;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
...VARIOUS INITIALIZATIONS HERE ARE OMITTED.
glLoadIdentity();
glClearColor(0.7, 0.7, 0.7, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glVertexPointer(3, GL_FLOAT, 0, vertices);
glVertexPointer(3, GL_FLOAT, 0, allVerts);
glColorPointer(4, GL_FLOAT, 0, colors);
glNormalPointer(GL_FLOAT, 0, normals);
NSMutableArray *tempRow;
Cube *tempCube;
for (int i = 1; i <= cubes.tileRows; i++)
{
tempRow = [cubes rowAtIndex:i-1];
for (int j = 1; j <= cubes.tileCols; j++)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
tempCube = [tempRow objectAtIndex:j-1];
texCoords[12] = (GLfloat)tempCube.frontFace.left;
texCoords[13] = (GLfloat)tempCube.frontFace.top;
texCoords[14] = (GLfloat)tempCube.frontFace.left;
texCoords[15] = (GLfloat)tempCube.frontFace.bottom;
texCoords[16] = (GLfloat)tempCube.frontFace.right;
texCoords[17] = (GLfloat)tempCube.frontFace.top;
NSLog(@"frontface left: %f %f", tempCube.frontFace.left, texCoords[12]);
glLoadIdentity();
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glTranslatef(gridOffsetX + (tileSpacing * (GLfloat)i), gridOffsetY + (tileSpacing * (GLfloat)j), gridOffsetZ);
glRotatef(rot, 0.0, 1.0, 0);
glRotatef(90, 0.0, 0.0, 1.0);
//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, cubeFaces);
//glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_BYTE, cubeStripOne);
glDrawArrays(GL_TRIANGLES, 0, 36);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
various arrays are given values in above the shown code: I haven’t included them because they’re pretty uncontentious.
Any Ideas?