Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (616)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [partly solved] separating alpha channel  (Read 1290 times)
0 Members and 1 Guest are viewing this topic.
Offline TheBohemian

Junior Devvie

Java will rule them all!

« Posted 2004-03-23 14: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.



my favorite OS:
Java 1.5 -> 1.4 converter:
Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #1 - Posted 2004-03-23 15: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.

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

Junior Devvie

Java will rule them all!

« Reply #2 - Posted 2004-03-23 16: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.



my favorite OS:
Java 1.5 -> 1.4 converter:
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TheBohemian

Junior Devvie

Java will rule them all!

« Reply #3 - Posted 2004-04-02 08:21:09 »

I have solved the problem of getting a separate image from the alpha channel here:;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?



my favorite OS:
Java 1.5 -> 1.4 converter:
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (18 views)
2015-09-03 00:41:28

Andrew_3ds (29 views)
2015-09-01 19:08:10

afikri (20 views)
2015-08-31 09:30:22

afikri (27 views)
2015-08-31 09:30:07

afikri (14 views)
2015-08-31 09:27:24

afikri (17 views)
2015-08-31 09:26:40

Roquen (30 views)
2015-08-29 11:30:54

GamerC4 (38 views)
2015-08-22 20:38:50

GamerC4 (36 views)
2015-08-22 20:37:18

GamerC4 (42 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!