Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
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 1127 times)
0 Members and 1 Guest are viewing this topic.
Offline TheBohemian

Junior Member




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.

cya

TheBohemian

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

JGO Kernel


Medals: 56
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.

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

Junior Member




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.

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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TheBohemian

Junior Member




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:
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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!