Hey folks. A PNG I saved using paint works fine, but when I save it with the GIMP, adding transparency, it appears garbled, as static.
my code is as follows:
private static BufferedImage readPNGImage( String resourceName ){
try{
URL url = MediaUtil.getResource( resourceName );
if ( url == null ){
throw new RuntimeException( "Error reading resource " + resourceName );
}
BufferedImage img = ImageIO.read( url );
java.awt.geom.AffineTransform tx = java.awt.geom.AffineTransform.getScaleInstance( 1 , -1 );
tx.translate(0, -img.getHeight( null ));
AffineTransformOp op = new AffineTransformOp( tx , AffineTransformOp.TYPE_NEAREST_NEIGHBOR );
img = op.filter( img , null );
return img;
}
catch ( IOException e ){
throw new RuntimeException( e );
}
}
private static void makeRGBTexture( GL gl , GLU glu , BufferedImage img , int target , boolean mipmapped ){
ByteBuffer dest = null;
switch( img.getType() ){
case BufferedImage.TYPE_3BYTE_BGR:
case BufferedImage.TYPE_CUSTOM:
byte[] data1 = ( (DataBufferByte) img.getRaster().getDataBuffer() ).getData();
dest = ByteBuffer.allocateDirect( data1.length );
dest.order( ByteOrder.nativeOrder() );
dest.put(data1, 0, data1.length);
break;
case BufferedImage.TYPE_INT_RGB:
int[] data = ( (DataBufferInt) img.getRaster().getDataBuffer() ).getData();
dest = ByteBuffer.allocateDirect( data.length * BufferUtils.SIZEOF_INT );
dest.order( ByteOrder.nativeOrder() );
dest.asIntBuffer().put( data , 0 , data.length );
break;
default:
throw new RuntimeException( "Unsupported image type " + img.getType() );
}
if (mipmapped){
glu.gluBuild2DMipmaps(target, GL.GL_RGB8, img.getWidth(), img.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
}
else{
gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, dest);
}
}
None of this code is my own, so I’m not really sure how to debug it. I’d love any kind of help!
Thanks,
Nick