Update Texture Image

Hello,



I have to update a texture at each frame (from an image taken by a firewire camera). I can display the first image but after, it doesn't change.

Here is the code in update():


           texture.setImage(TextureManager.loadImage(textureRGB,false));
           textureRGB_state = display.getRenderer().createTextureState();
           textureRGB_state.setTexture(texture);
           textureRGB_state.setEnabled(true);
           tbb.clearRenderState(StateType.Texture);
           tbb.setRenderState(textureRGB_state);
           tbb.updateRenderState();


where textureRGB is my Image (which is well updated, i checked by saving in files), tbb is a TerrainBlock.
I tried reinitialising "texture" like this:

texture = TextureManager.loadTexture(textureRGB,Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear,true);


It works, but a memory error occurs after a few seconds.
Is there another method to update the texture or must I use TextureManager.loadTexture and free some object ? (and if I have to, how ?).

Thanks.



EDIT: I found a solution by using "TextureManager.releaseTexture(texture);" before TextureManager.loadTexture. But is it possible to avoid release/reload and just change the image ?

Maybe try:


Renderer.updateTextureSubImage(
   <Texture> dstTexture,
   <int> dstX,
   <int> dstY,
   <Image> srcImage,
   <int> srcX,
   <int> srcY,
   <int> width,
   <int> height
 )

Thanks :wink:

It works

How can i get Image type data ? I tried like below


Image myImage;
myImage = TextureManager.loadImage(
getClass().getResource("textures/heroes/1/front/frames/demo_12.png"),
false
);

Renderer.updateTextureSubImage(texture, 0, 0, myImage, 0, 0, 256, 256);



but i receive some error. What i need to put in Renderer place ?
Thanks a lot for any advice.

Ok problem solved:


Renderer r = display.getRenderer();



But anyway it is not fast enought to put it in update.

Is it any other way to fast load small textures ?. Maybe i could load all textures in init state and then only change them in update state. But is there some fast "preload" texture function ?

Thanks for any advices.