Hello Guest

Loading a 32-bit bmp from inside a jar

  • 3 Replies
Loading a 32-bit bmp from inside a jar
« on: November 14, 2005, 22:13:29 »
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:

Code: [Select]

public static int loadBMP32(String path, Object parent)
        IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();

        InputStream is = new BufferedInputStream( parent.getClass().getResourceAsStream(path));

       ByteBuffer bb = ByteBuffer.allocateDirect(is.available()).order(ByteOrder.nativeOrder());
       byte[] ba = new byte[(int)is.available()];
        catch(IOException ioe)
        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


Offline oNyx

  • ***
  • 177
  • 弾幕
Loading a 32-bit bmp from inside a jar
« Reply #1 on: November 14, 2005, 23:16:48 »
Is there a reason why you dont use 32bit tgas instead? :?

Loading a 32-bit bmp from inside a jar
« Reply #2 on: November 14, 2005, 23:47:21 »
We're using Photoshop to create the images and every time we try to save one as a 32-bit targa, the file inevitably ends up as 24-bit targa. The .bmp extension has no problem saving as 32-bit.

I'd love to use .tga files, so if anyone knows how to make one that's 32-bit I'm all ears.

Loading a 32-bit bmp from inside a jar
« Reply #3 on: November 15, 2005, 04:24:19 »
Hey, figured out how to make 32-bit targa files in the GIMP. With just a quick change to the file type above the code works fine. Cool, thanks for the suggestion.