LWJGL
May 19, 2013, 01:21:11 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Loading a 32-bit bmp from inside a jar  (Read 4099 times)
firetie
Newbie
*
Posts: 3


« on: November 14, 2005, 14: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:

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
    }
Logged
oNyx
Talks Too Much
***
Posts: 177


弾幕


« Reply #1 on: November 14, 2005, 15:16:48 »

Is there a reason why you dont use 32bit tgas instead? :?
Logged

firetie
Newbie
*
Posts: 3


« Reply #2 on: November 14, 2005, 15: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.
Logged
firetie
Newbie
*
Posts: 3


« Reply #3 on: November 14, 2005, 20: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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!