Easy way to load a texture in LWJGL?

Okay, so now that devIL isn’t supported anymore it seems I’m expected create my own texture loader (I didn’t have to do this in JOGL!), so I was wondering if there was a easier way to load a texture (.png). Thanks in advance.

Fmod and Devil were both removed for LWJGL2+, the recommended replacement is a library called slick-util (note different from slick2d). You should be able to load various texture and sound formats with it.

you can get it from http://slick.cokeandcode.com/downloads/util/ and the javadoc is located at http://slick.cokeandcode.com/javadoc-util/

Its pretty easy to use, just download the package and have a look at the examples included in the source code on how to use it.

int textureID = TextureLoader.getTexture(".PNG",this.getClass().getClassLoader().getResourceAsStream(“image.png”),true).getTextureID();

Thank you very much. I’m now using Slick :slight_smile:
Problem when I use textures though :frowning:

 texture.bind();
        
        GL11.glBegin(GL11.GL_QUADS);
        // Front Face
	        GL11.glTexCoord2f(0.0f, 0.0f);
	        GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
	        GL11.glTexCoord2f(1.0f, 0.0f);
	        GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
	        GL11.glTexCoord2f(1.0f, 1.0f);
	        GL11.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
	        GL11.glTexCoord2f(0.0f, 1.0f);
	        GL11.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
        GL11.glEnd();     

that’s a non power of two texture i think.

So I’m trying to get a tech demo out of Ultra GL as a JWS App, and for some reason the TextureLoader from Slick-Util doesn’t want to see my .png from inside the jar file. Here’s the code.


try {
			texture = TextureLoader.getTexture("PNG", new FileInputStream("data/wall.png"));
		} catch (IOException e) {
			e.printStackTrace();
		

You need to do:


texture = TextureLoader.getTexture("PNG", this.getClass().getClassLoader().getResource("data/wall.png").openStream());

This should work, or be very close to something that works. You need to use getResource() to easily fetch resources that are inside jars.

Actually, for (old, bugged versions of?) Java WebStart you need to do:

Thread.currentThread().getContextClassLoader().getResourceAsStream("abc/def/Ghi.jkl");

This works everywhere.

If you are using Slick, you can use:


texture = TextureLoader.getTexture("PNG", ResourceLoader.getResource("data/wall.png"));

This will find it both in the classpath and on the filesystem.