PNG texture coming up garbled.

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

Notice that the glTexImage calls are sending RGB, not RGBA. You need to tweak that so that it reads 4 pixels at a time rather than 3.

I would also suggest you look at the texture utility classes in com.sun.opengl.util.texture and the demos.texture.TestTexture example in the jogl-demos workspace. These help abstract away the loading and display of textures including PNGs.