This was working a while back on JOGL.
Ever since I installed the JSR-231 build it causes issues. Is this a known issue?
I’m loading a 32bit PNG.
Here is the result:
Here is my code(just in case)
private ArrayList<Texture> loadedTextures;
private Texture loadedTexture;
public TextureLoader(DataGL glData) {
loadedTextures = new ArrayList<Texture>();
GL gl = glData.getGL();
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnable(GL.GL_BLEND);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
public Texture loadTexture(DataGL glData, String location)
{
GL gl = null;
Texture tmpTex = null;
BufferedImage img = null;
File file = null;
ByteBuffer imgBuff = null;
IntBuffer texId = null;
if(isLoaded(location)) {
tmpTex = loadedTexture;
}
else {
gl = glData.getGL();
texId = BufferUtils.newIntBuffer(1);
file = new File(location);
assert file.exists();
try {
img = ImageIO.read(file);
} catch (IOException e) {
e.printStackTrace();
}
byte[] tmpImgBuff = ((DataBufferByte)img.getData().getDataBuffer()).getData();
int bpp = img.getData().getNumBands();
imgBuff = BufferUtils.newByteBuffer(tmpImgBuff.length);
imgBuff.put(tmpImgBuff);
bindTextureToVRAM(gl, imgBuff, texId, img, bpp);
tmpTex = new Texture(location, texId.get(0), img.getWidth(), img.getHeight());
img.flush();
imgBuff.clear();
texId.clear();
}
return tmpTex;
}
private void bindTextureToVRAM(GL gl, ByteBuffer imgBuff, IntBuffer texId, BufferedImage img, int bpp) {
gl.glGenTextures(1, texId);
gl.glBindTexture(GL.GL_TEXTURE_2D, texId.get(0));
gl.glTexImage2D(
GL.GL_TEXTURE_2D,
0,
bpp != 4 ? GL.GL_RGB8 : GL.GL_RGBA8,
img.getWidth(),
img.getHeight(),
0,
bpp != 4 ? GL.GL_RGB : GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE,
imgBuff
);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
}
private boolean isLoaded(String location) {
boolean isLoaded = false;
for (Texture tex : loadedTextures) {
if(tex.getTextureLocation().equals(location)) {
loadedTexture = tex.clone();
isLoaded = true;
break;
}
}
return isLoaded;
}