How to make a textureLoader

I’m trying to cut my use of slick by making my own TextureLoader, I don’t need any fancy tricks.
I was wondering if anyone had a tutorial on loading textures from PNG format

I’m currently looking through the slick source code.

In particular, once reading and decoding the file, how should it be arranged for OpenGL to use it?

OpenGL only cares for pure RGB/RGBA data. You have to decode PNG into that pure data. Good luck!

So put it all into a ByteBuffer, how does OpenGL read the texture, top left across then down a row?

Sorry for all the questions :3

In particular the Textures and Buffers page.

Refer to this post which shows how to fix NPOT images when not supported in hardware.

That should be enough for most 2D purposes. You can take a peek at some more advanced texture loading concepts here (compressed textures, different formats, different targets, mipmaps, etc).

http://pastebin.java-gaming.org/3fe088a3a3f
Here’s my code for this.
Converts a BufferedImage to a ByteBuffer and back.

Enjoy!

Thank you, it’s actually a really good idea to let awt handle the decoding :3

Not really. It introduces a huge dependency that isn’t necessary for something so simple, and ImageIO can be pretty slow sometimes.

If you are going to use AWT, you can use this technique which may lead to better performance.

:slight_smile:

JOGL 2.0 uses PNGJ for that, it works very well even under Android.

@Joshua Waring - Have a look at the PNGDecoder tutorial found on the LWJGL wiki here.

PNGDecoder is one of the most lightweight and fastest Java PNG decoders you’ll find (being just one class and no dependency on AWT), the rest is just plugging the raw decoded data into OpenGL.