MatthiasM has written some extremely awesome texture loaders spun off from TWL that don't require TWL itself. It supports BMP, JPG, PNG, and TGA (no GIF that I can see). It's asynchronous, so you get a callback when the texture is loaded and you can keep on doing your own thing in the meantime (like displaying a loading screen or downloading other resources) without having to manage any threads.
http://hg.l33tlabs.org/TextureLoader/Well - it supports 3 modes of operations:
- fully managed by using the TextureManager.getTexture() function - this one is asynchronous (eg loads in a background thread)
- synchronous using Texture.loadTexture() function
- using the TextureLoader* classes to get the bytes directly
The asynchronous TextureManager method will render a transparent 2x2 pixel texture when the desired texture has not yet (or could not) been loaded.
Textures which are not used for some time are also unloaded.
And there is no need to manage threads - the only thing you need to do in your main loop when you want to use the TextureManager is:
1 2 3 4 5 6 7 8 9 10 11 12
| AsyncExecution async = new AsyncExecution(); TextureManager tm = new TextureManager(async); ... while(!Display.isCloseRequested()) { ... async.executeQueuedJobs(); tm.nextFrame(); ... Display.update(); } |