This class will load transparent or non-transparent images into some buffer with there width and height
The transparent color will the pixel color at the lower left of the image.
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.awt.Color;
import javax.imageio.ImageIO;
public class StaticImages {
public static ByteBuffer _32BITImages[] = new ByteBuffer[32];
public static int _Width[]= new int[32];
public static int _Height[]= new int[32];
public static void setBTrans(BufferedImage name,int temp){
for (int _yi = 0; _yi<name.getHeight();_yi++){
for (int _xi = 0; _xi<name.getWidth();_xi++){
if (name.getRGB(_xi,_yi)==temp)
name.setRGB(_xi,_yi,0);
}//END X FOR STATEMENT
}//END Y FOR STATEMENT
}//END METHOD
private static int fixRGB(int num){
int Alpha = 0xFF000000;
int Red = 0x00FF0000;
int Green = 0x0000FF00;
int Blue = 0x000000FF;
int finalR = 0;
Red = num & Red;
Red = Red << 8;
Green = num & Green;
Green = Green << 8;
Blue = num & Blue;
Blue = Blue << 8;
Alpha = num & Alpha;
Alpha = Alpha >>> 24;
finalR = Red | Green | Blue | Alpha;
return finalR;
}//END METHOD
public static void Load32BitImg(String name,int id,java.awt.GraphicsDevice GD,boolean trans){
try{
Image imgTemp;
imgTemp = (Image)ImageIO.read(new File(name));
ByteBuffer buf;
//System.out.println("Found File");
BufferedImage Bimg = GD.getDefaultConfiguration().createCompatibleImage(imgTemp.getWidth(null),imgTemp.getHeight(null),Color.BITMASK);
Bimg.getGraphics().drawImage(imgTemp,0,0,null);
if (trans)
setBTrans(Bimg,Bimg.getRGB(0,Bimg.getHeight()-1));
buf = ByteBuffer.allocateDirect((Bimg.getWidth()*Bimg.getHeight())*4);
for (int y = 0; y< Bimg.getHeight();y++){
for (int x = 0; x< Bimg.getWidth();x++)
buf.putInt(fixRGB(Bimg.getRGB(x, Bimg.getHeight()-y-1)));
}//END FOR LOOP
//System.out.println("BUFFER MADE");
_32BITImages[id] = buf;
_Width[id] = Bimg.getWidth();
_Height[id] = Bimg.getHeight();
}catch(IOException ie){
System.out.println("Error Reading Image");
}//END TRY AND CATCH STATEMENT
}//END METHOD
}//END CLASS
How to draw those images.
tempGL.glEnable(GL.GL_BLEND);
StaticImages._32BITImages[imgID].clear();
tempGL.glRasterPos2i(X Position,Y Position);
tempGL.glDrawPixels(StaticImages._Width[imgID],
StaticImages._Height[imgID],
GL.GL_RGBA,
GL.GL_UNSIGNED_INT_8_8_8_8_REV,
StaticImages._32BITImages[imgID]);
tempGL.glDisable(GL.GL_BLEND);