try {
// Open the PNG file as an InputStream
//URL file = ClassLoader.class.getResource(path);
// Link the PNG decoder to this stream
PNGDecoder decoder = new PNGDecoder(url.openStream());
// Get the width and height of the texture
textureWidth = decoder.getWidth();
textureHeight = decoder.getHeight();
// Decode the PNG file in a ByteBuffer
imageBuffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(imageBuffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
imageBuffer.flip();
} catch (IOException e) {
throw new RuntimeException("Clean this up:" + e);
}
}