Animating Textures

Texture myTexture = TextureManager.loadTexture (myCopy,Texture.MM_LINEAR,Texture.MM_LINEAR,true);

Texture manager caches all the textures. So if you are making a new texture every iteration and the load that texture you will run out of memory.

An easy solution would be to load all the textures you need during initialization, put them in Texture[] array and loop through it in the update code.

Right, or a quick hack would be to delete the texture from your card and the cache before changing to the new one.

to renanse:

I don't think you have looked at his code at all :P.

The problem there is something that should be done during initialization is done every frame: unpacking a texture one pixel at a time, making a new texture and removing old textures from TextureManager will not result in good fps. Saving memory here is not an issue, because the whole BufferedImage is loaded into the memory (and copied every frame). In fact, buffering textures during initialization and letting that buffered image go will save memory and memory bandwidth.

No, there’s not enough time in the day to read through all of the code that is posted here anymore.    Ah well… I’ll just resist the urge to post [next time]

lex said:

to renanse:
I don't think you have looked at his code at all :P.

An unneccessary and offensive statement. Renanse's solution is "a quick hack", just as he says in  his post. Your approach, lex, is "an easy solution" instead, which isn't that much a difference really. I am very happy to have a bit of insight from the core developers in almost every thread on this forum, and I wouldn't want to lose that because sometimes those answers don't solve the OPs problem in the "best possible" way.

Back on topic:
Depending on the situation the animated texture is presented in the "best possible way" might also be any of the following:

  • to use a big texture containing all frames of the animation - and only change texture coordinates in the render/update loop

  • to use a pixel shader solution

  • to use one of the video texture solutions that are somewhere on the forum

and probably more I haven't thought of.
Quote from: lex on Today at 01:57:17 PM
to renanse:
I don't think you have looked at his code at all Tongue.

An unneccessary and offensive statement.

There is nothing offensive about it... I have said more offensive things :)
I might not have ideal people skills because I call things what they are and I don't brown nose, so please forgive me.

Before anyone gets angry at anyone else I figured I'd step in and tell you all to shut up.  :stuck_out_tongue:

Any post on just about any forum has to be taken pretty light-hearted or it will all turn into flame wars…as appealing as that sounds to me I don't think anyone intended any harm…except me of course by my "shut up" comment. :slight_smile:

yes, sir!  }:-@

Sorry, did not mean to sound offended at all… just stressed, tired and embarrassed.  }:-@

If you want to make it even faster you could switch different textures into the same textureSate instead of switching states.


Then you dont need to call updateRenderState() every frame, only once at the end of initialization block.