views:

154

answers:

0

I'm building a game that has an array of 7 * 5 tiles, similar to Scrabble tiles. The two main faces are supposed to have different letters on them.

I've created a single geometry that I reuse by translating in x and y. I can change the letter that is mapped to the face of ALL the tiles, by setting the values in my glTexCoordPointer. My DrawView routine contains a nested loop that retrieves the values that glTexCoordPointer should have to render the appropriate letter. I can update the values in the array, but it has no effect.

I allocate the glTexCoordPointer outside the loop(s), and then modify it in the inside loop. But the values used are whatever glTexCoordPointer is initialized with.

I assume that openGL is copying this array somewhere, and that I have to do something to tell it to forget about the values it loaded, and load new ones. Is this correct?

Here's the main section of the drawView method, after I define the various arrays I use. I define the texCoords array with values that map a particular letter onto the face: that's what appears in the rendering, even though I can see that there values are changing in the array, per the logging in the inner loop.

 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);

        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);

static NSTimeInterval lastDrawTime;
if (lastDrawTime)
{
    NSTimeInterval timeSinceLastDraw = [NSDate timeIntervalSinceReferenceDate] - lastDrawTime;
    rot+=30 * timeSinceLastDraw;                
}
//NSLog(@"rot is %f", rot);
lastDrawTime = [NSDate timeIntervalSinceReferenceDate];