Search code examples
javapngtextureslwjglslick2d

Slick util error with png [with solution]


I've searched this site for a definitive answer to my problem but it seems that everyone has a different answer as to the origin of the problem but no specific solutions.

I'm using the Slick-Util library with lwjgl and when I load my texture file for my basic shape, the program take a bit longer to start (as opposed to being instantaneous without the texture loading) and despite the fact that I get my texture on screen, I get this error in the console (which could explain the initial loading lag)

Sat Mar 07 05:35:42 EST 2015 WARN:class org.newdawn.slick.opengl.PNGImageData failed to read the data
java.lang.UnsupportedOperationException: Unsupported format for this image

the code where I load the file:

public int loadTexture(String fileName)
{
    Texture texture = null;
    try {
        texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + fileName + ".png"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    int textureID = texture.getTextureID();
    textures.add(textureID);
    return textureID;
}

I'm using a regular png file, non-interlaced, 8 bits 256 x 256 without transparency. Any idea why i get this error, how I can prevent it and if I could use something else than slick-util that would not give me that error?

A file that works:

a file that works

and one that does not:

this one does not


Solution

  • I found a solution to the annoyance of having to use regular paint to draw all my textures:

    1. Create the image in paint.net as usual despite the compatibility problem.

    2. Select all and copy the entire image.

    3. Open a new document in regular paint and paste the texture to it.

    4. Save the image with regular paint as a .PNG and everythign should be working fine!

    If your texture is already saved in a file that throws an error with slick utils, open it and repeat steps 2-4