October 3, 2008, 9:35am
Texture.createSimpleClone() copies everything concerning the Texture except the image itself, but I need that too.
What I am doing is I have a TextureRenderer that renders an animated model to a Texture, kind of like ImposterNode is doing it. This is already working. I need a Texture that shows the animation of the model at time 0.0f.
After the TextureRenderer is set up I want to somehow retrieve a copy of the Texture:
Texture2D textureClone = (Texture2D) str.getTexture().createSimpleClone();
((LWJGLTextureRenderer)str.getTextureRenderer()).copyToTexture(textureClone, texWidth, texWidth);
does not work because the texturerenderer will keep rendering to the cloned Texture. I want it to write the texture once and then somehow detach it from the renderer.
October 7, 2008, 9:55am
right now i can come up with this:
Texture2D textureClone = new Texture2D();
((LWJGLTextureRenderer) str.getTextureRenderer()).copyToTexture(textureClone, texWidth, texWidth);
I call this after setting up the scene in the texturerenderer. however the Texture 'textureClone' is blanc.
Not sure if this would work, but seeing as it’s just a normal Java object like everything else I imagine it would. I created a cloning utility in jCommon that provides several methods of deep cloning:
It defaults to use the reflection method (which is by far the fastest), but you can always configure it to use a more typical deep cloning style if you prefer.
October 7, 2008, 12:51pm
Deep cloning wont do the job, since the textureId is what identifies the texture to OGL, and using the same textureId will result in overwriting the texture.
Set up two textures for RTT, after you render to the first texture, use that as your original clone, after that use the second to render to afterwards.
October 7, 2008, 12:58pm
thanks darkfrog for the answer but i got it to work just now like this:
animatedTexture = new Texture2D();
stillTexture = new Texture2D();
and in the draw() method, i render the animatedTexture.
this is somehow worse than copying the initial texture since it is being drawn twice, but it is only done once in the constructor which is called at the startup of the game. :)
Did you manage to clone textures so that they have separate images?
Any success, please?