DevIL texture loader

I had been using Kevglass’ texture loader (thanks for that ;D ) for a long time, but after deciding to use DevIL and needing multithreaded texture loading, I found myself wanting to write a new one from scratch. So this loader is still fairly simple, and mostly just for 2D games (doesn’t generate mipmaps or anything), but it does flip your textures, convert to power of two dimensions, use DevIL, and supports loading on one thread and creating the texture on another. Here are the classes:

http://www.cyntaks.com/projects/source/TextureLoader.java
http://www.cyntaks.com/projects/source/Texture.java

I’ll write some example code using the TextureLoader on two threads if anyone is interested. Although I do try to explain it with comments in the code, it may be a bit non-intuitive for some people to use.

For anyone who doesn’t know, the reason you want to load and create the texture on multiple threads is this: loading your textures can take a while and chances are you want to show a progress bar or something while this takes places. The obvious way to do this is to just load the texture on another thread, problem is that textures must be created on the same thread that they will be used on. This code splits the process into two parts so that you can load on the new thread and create on your rendering thread.

Enjoy!

Oh yeah, and if anyone looks through the code and finds that I’m doing something that could potentially blow up someone’s computer, let me know ;D

Why don’t you use “static” instead of your private constructor and declare all the methods in the TextureLoader static; would be easier to handle and faster to use…

WiESi

I suspect it was an attempt to make the thing more future proof, you might want multiple TextureLoader instances (maybe for texture context) at some point one day.

Kev

yeah what kev said :slight_smile:

Actually my reasons weren’t quite as good, I don’t remember why I chose to do it that way but I probably figured usage would be pretty much the same either way. I probably just did it because I think I should be creating objects instead of using classes with static methods for some reason.

is this compatible with the space invaders demo? (ie if i switch the files it won’t know the difference) ?

if so this would be great and should replace it in the lwjgl library, most newbies (including me) use textureLoader and texture for there games so this would be a welcome addition!

It actually can’t be swapped with the space invaders texture loader. There is more you have to do if you want to use multi-threaded loading and I’m not sure if my methods for single-threaded loading are the same as the invaders loader or not (they will certainly be similar though). I don’t know if its a good replacement because it probably hasn’t been tested much, all I can say is that I’ve been using it and havn’t had any problems :slight_smile: