[partly solved] separating alpha channel

To use texture masking I read in many tutorials that a separate alpha mask texture is needed. Since I don’t want to store 2 files for each image (alpha channel is included in PNGs anyway …) I need to generate a BufferedImage from the alpha channel of the source image.

I thought of something like this:

new BufferedImage(colormodel, sourceImage.getAlphaRaster(), …);

The problem is that Java complains about the colormodel being wrong. How can I determine which is right for the alpha raster?


I wonder if this is the only way to get masked textures to work because OpenGL supports textures in RGBA format which means that the alpha channel is included ???

Thanks for any help.

Have a look though the posts in this forum, there was a good texture loader set of classes that I use that work great, saved me a bunch of time :slight_smile: IIRC, they defined their own custom colour model for loading purposes.

I know this texture loader and but it doesn’t do what I want. The colormodels defined there use a data layout that is compatible to OpenGL.

Maybe I did not explain correctly what I want: My aim is to generate an image containing only black and white. The source for this should be the alpha channel of another image.

I have solved the problem of getting a separate image from the alpha channel here:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1080183633;start=0#1

The problem now is that the masking information contained in the mask image is not suitable for OpenGL. The opaque and transparent areas are inverted. Thats why you have to invert the color once more to get it to work with JOGL.
Somewhere on the net I found a nice piece of code which uses BufferedImageOps for the invert operation.
At first the greyscale image (described in the linked post) has to be copied into an RGBA type image and then you can this code to invert its colors:


        byte[] invert = new byte[256];
        for (int i = 0; i < 256; i++) {
            invert[i] = (byte)(255 - i);
        }
        
        java.awt.image.BufferedImageOp invertOp = new java.awt.image.LookupOp(new java.awt.image.ByteLookupTable(0, invert), null);
        
        texImage = invertOp.filter(texImage, null);

Now you can use the usual routine to create the OpenGL texture (accessing databuffer, wrapping into a ByteBuffer, glTexParameteri, glGenTexture2D).

Now after all I got this to work but in chapter 9 under ‘Texture Functions’ in the red book it is stated that with GL_DECAL RGBA textures are drawn like insignias. Thats exactly what I wanted. Somehow the transparent areas do not show the colors behind the texture but instead the color which was last set with glColor3/4f …
Any ideas what I am doing wrong?