I'm following the answer from this thread: Binding Multiple Textures to One Mesh in OpenGL ES 1.1
My implementation doesn't seem to be working and I don't know why.
Here are the facts of my code:
- textureArray is an NSMutableArray populated by GLKTextureInfo objects
- groupMesh is an array of a struct that contains:
- a pointer to the place in the index array that we want to get indices from.
- the size of the index data
-
- I have one element array buffer for my vertices and one for my indices
I decided to make a for loop. In each iteration I bind a different texture from the GLKTextureInfo array, and I change the pointer to the area of memory of the index data I want to draw with the texture that I just bound.
-
for (int i = 0; i<mesh->numMeshes-1; i++)
{
glBindTexture(GL_TEXTURE_2D,
[(GLKTextureInfo *)[textureArray objectAtIndex:i] name]);
glDrawElements(GL_TRIANGLES,
mesh->groupMesh[i].indexDataSize*4,
GL_UNSIGNED_INT,
mesh->groupMesh[i].indexPointer);
}
The first texture in the array is a tree bark texture, the second texture is tree leaves.
The textures aren't binding after the first iteration however. Which is giving this kind of result:
http://img69.imageshack.us/img69/5138/tbko.png
I forced the loop to test if my theory was correct and changed objectAtIndex:i to objectAtIndex:1, and the leaf texture appeared all over:
http://img266.imageshack.us/img266/5598/c05n.png
So it just seems to be glBindTexture that isn't working, is it because opengl is already in the draw state? Is there a way around this?
Note:(I asked a similar question yesterday, but now I've done a bit more research and still I don't know what I'm doing wrong).