I'm trying to blend images using the built in alpha layer on my 32-bit .bmp, but it's not working right. Instead of using the alpha layer is uses the default black values in the image for transparency. I'm wondering if there's a problem in how I'm loading the file. The code I'm using is modified from a tutorial from NeHe Productions, put into a static class and goes like this:
public static int loadBMP32(String path, Object parent)
{
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
InputStream is = new BufferedInputStream( parent.getClass().getResourceAsStream(path));
try
{
ByteBuffer bb = ByteBuffer.allocateDirect(is.available()).order(ByteOrder.nativeOrder());
byte[] ba = new byte[(int)is.available()];
is.read(ba);
bb.put(ba);
bb.clear();
IL.ilLoadL(IL.IL_BMP,bb);
IL.ilLoadFromStream(is,IL.IL_BMP);
is.close();
}
catch(IOException ioe)
{
System.out.println("screwed");
}
IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4);
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGBA, IL.IL_BYTE, scratch);
// Create A IntBuffer For Image Address In Memory
IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buf); // Create Texture In OpenGL
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
// Typical Texture Generation Using Data From The Image
// Linear Filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
// Linear Filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
// Generate The Texture
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch);
return buf.get(0); // Return Image Address In Memory
}