Title pretty much explains what is happening. It loads my images fine except for ones with transparency in them.
Here's what I am trying to do:
public class TextureLoader {
public static Texture loadPNG(File dir, String texName) {
File f = new File(dir+"/"+texName+".png");
try {
if(!f.exists()) throw new IOException();
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
IntBuffer comp = BufferUtils.createIntBuffer(1);
ByteBuffer buffer = STBImage.stbi_load(f.toString(),w,h,comp,4);
if(buffer == null) throw new IOException();
int imgWidth = w.get();
int imgHeight = h.get();
int texId = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, imgWidth, imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
buffer.clear();
Logging.sysMsg("Loaded texture " + texName + ".png | " + imgWidth + "x" + imgWidth);
return new Texture(texId, imgWidth, imgWidth);
} catch (IOException e) {
Logging.errMsg("Texture " + texName + " doesn't exit");
if(!texName.equals("default"))
return TextureHandler.defaultTexture;
else return null;
}
}
}
You can get the reason an stbi load fails using the stbi_failure_reason() function.
So change the error test to this:
if(buffer == null) {
throw new IOException(STBImage.stbi_failure_reason());
}
and see what STBI has to say about it.
Giving me this error:
<22:42.46> [ERROR #3] PNG not supported: 1/2/4/8-bit only
PNG images with 16-bits per channel are not supported.
Okay. I will just have to resave all my images with different bit depth. I tried it on one and it loaded just fine. Thanks.