Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  [partly solved] separating alpha channel  (Read 810 times)
0 Members and 1 Guest are viewing this topic.
Offline TheBohemian

Full Member
**

Posts: 236


Java will rule them all!


« on: 2004-03-23 09:34:03 »

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  Huh

Thanks for any help.

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline Orangy Tang

JGO Kernel
*****

Posts: 2960
Medals: 37


Monkey for a head


« Reply #1 on: 2004-03-23 10:08:28 »

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 Smiley IIRC, they defined their own custom colour model for loading purposes.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline TheBohemian

Full Member
**

Posts: 236


Java will rule them all!


« Reply #2 on: 2004-03-23 11:03:36 »

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.

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Games published by our own members! Go get 'em!
Offline TheBohemian

Full Member
**

Posts: 236


Java will rule them all!


« Reply #3 on: 2004-04-02 03:21:09 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
        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?

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.155 seconds with 21 queries.