Log in or register to post comments

Change texture

January 13, 2013 - 3:28am #1

 

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 allocinit];

            

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

January 14, 2013 - 3:17am #4

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

 

 

The textures work.   If I try

January 14, 2013 - 1:27am #3

The textures work.

 

If I try to switch from "first.png" to "second.png" the texture "first.png" will show up correct and after switch the object will be black.

If I try to switch from "second.png" to "first.png" the texture "second.png" will show up correct and after switch the object will be black.

I had my battle with the power of two textures...

 

Hi qilin, It could be that

January 14, 2013 - 1:24am #2

Hi qilin,

It could be that your textures are not a power of 2 in size?

 

Power Of Two (POT) textures have a size that is a power of 2 in each dimension:
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, etc..
 
And they don't have to be square: i.e. 512x64 will work.
 
Try one of these sizes and let me know how you get on.
 
thanks,
 
N
Log in or register to post comments