Replacing textures...

So I’ve got an issue in that I’m binding three textures and it appears that whatever I bind first is there in the background of the second, and so on. So for example, if I have a ball with an alpha channel as texture[0], and a stick with an alpha as texture[1] and a background image as texture[2] then when I render the ball I see that just fine, then for the stick I see the stick and behind it I see the ball. The landscape is fine as it has no alpha but if I bind it first then I see the landscape instead of a transparent background throughout the others.

I thought to try to explicitly make sure I’m replacing the texture, but here’s how I’m loading the images, via a function deciding whether to create a mipmap and the texture index:

glGenTextures(1, &textures[texture]);
glBindTexture(GL_TEXTURE_2D,textures[texture]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
if ( mipmap)
{
glGenerateMipmapOES(GL_TEXTURE_2D)
}
else
{
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexEnvi(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
}

Any ideas?? The only other thing I should mention is that this in on the iPhone and so there are a few quirks but most of these have been minor things like coordinate axes.

Got it - the memory wasn’t being zeroed out and so was being shared between the images.

calling memset after malloc zeroed out the memory and I’m done.

The following link was where I found the answer:

http://www.iphonedevsdk.com/forum/iphone-sdk-game-development/34307-multiple-textures-opengl-es.html