I'm having problems changing the loaded textures dynamically.
My project is based on image targets.
I need different textures loaded based on marker. I cannot load all textures, that will use alot of memory.
If I load the textures on start they show ok:
for (int i = 0; i < nTextures; ++i)
[textureList addObject: [NSString stringWithUTF8String:textureFilenames[i]]];
If I detect another marker I want to change textures (simplified code, just changing one texture but same problem)
Texture *tex = [[[Texture alloc] init] autorelease];
NSString *file = @"newtextureimage.png";
[tex loadImage:file];
[textures replaceObjectAtIndex:0 withObject:tex];
Object3D *obj3D = [[Object3D alloc] init];
obj3D.numVertices = NUM_PLANE_VERTEX;
obj3D.vertices = planeVertices;
obj3D.normals = planeNormals;
obj3D.texCoords = planeTexCoords;
obj3D.numIndices = NUM_PLANE_INDEX;
obj3D.indices = planeIndices;
obj3D.texture = [textures ObjectAtIndex:0];
[objects3D replaceObjectAtIndex:0 withObject:obj3D];
[obj3D release];
After texture is changed the object is all black.
The texture is known good. If I try to change in reverse order the texture is ok and after change black.
Any suggestions?
Hi,
just a quick intrusion in your discussion,
not sure about all the details on the iOS code but just speaking from an Android OpenGL perspective, you should have some OpenGL code like glTexImage2D () which updates the pixels of your texture with a new pixel buffer;
whenever you load a new image, you should make sure to retrieve the pixel buffer out of it and set it in the desired OpenGL texture using glBindTexture() and glTexImage2D().
Maybe double-check that you actually have such code executed upon image update (for everything else you can follow up with Nalin...)