Announcement: Be excellent to each other.


Caravel Forum : Other Boards : Anything : Java and Alpha Blending
New Topic New Poll Post Reply
Poster Message
bradwall
Level: Smiter
Avatar
Rank Points: 423
Registered: 02-12-2003
IP: Logged
icon Java and Alpha Blending (0)  
I can't figure a way to perform any type of alpha blending in Java. Does anyone know how?
What I am really trying to do is have font letters (like from JLabel) fade slowly. Just have it a solid letter, then become more transparent.
Does anyone have any thought on doing this with Java?

03-25-2005 at 05:04 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
stigant
Level: Smitemaster
Avatar
Rank Points: 1182
Registered: 08-19-2004
IP: Logged
icon Re: Java and Alpha Blending (+1)  
Well, I don't know what graphics library you are using, so I can't give you low level implementation details. However, alpha blending (in general) is basically just linear-interpolation between the rgb values that describe the color of your objects and those that describe the background.

Of course, you probably don't have pixel-by-pixel control over the color of your font, so that's probably useless to you.

[Edited by stigant at Local Time:03-25-2005 at 08:42 PM]

____________________________
Progress Quest Progress
03-25-2005 at 08:41 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
bradwall
Level: Smiter
Avatar
Rank Points: 423
Registered: 02-12-2003
IP: Logged
icon Re: Java and Alpha Blending (0)  
stigant wrote:
Well, I don't know what graphics library you are using, so I can't give you low level implementation details. However, alpha blending (in general) is basically just linear-interpolation between the rgb values that describe the color of your objects and those that describe the background.

Of course, you probably don't have pixel-by-pixel control over the color of your font, so that's probably useless to you.

[Edited by stigant at Local Time:03-25-2005 at 08:42 PM]

I appreciate your input.
Thanks for replying.
03-25-2005 at 09:14 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
stigant
Level: Smitemaster
Avatar
Rank Points: 1182
Registered: 08-19-2004
IP: Logged
icon Re: Java and Alpha Blending (+3)  
Do you have the ability to draw to an offscreen bitmap, or are you drawing/printing straight to the screen?

My experience here has been with Direct3D which allows you to draw to (multiple) offscreen bitmaps, then blit one onto another until you have the full image (sort of like layering transparencies) which you render to the screen. Something like this:

rgb_bitmap alpha_layer[screen_width][screen_height];
rgb_bitmap background[screen_width][screen_height];
double alpha_level = .5;  //this determines the transparency of the text.  use 1.0 for opaque text, 0.0 for invisible text etc.

scene.render(background);  //render the scene to the background bitmap
scene.render(alpha_layer); //render the scene to the alpha_layer as well so that the parts of the alpha_layer that are empty will not affect the background in the blend stage.  Alternatively, copy the background to the alpha_layer

//have the font object render "hello world" at the desired x and y coordinates to the alpha_layer
font.display_text(alpha_layer, "hello world", text_x, text_y);

for ( i = 0; i < screen_width; i++ ) {
    for ( j = 0; j < screen_height; j++ ) {
        background[i][j].red = alpha_level * alpha_layer[i][j].red + (1-alpha_level) * background[i][j].red;
        background[i][j].green = alpha_level * alpha_layer[i][j].green + (1-alpha_level) * background[i][j].green;
        background[i][j].blue = alpha_level * alpha_layer[i][j].blue + (1-alpha_level) * background[i][j].blue;
    }
}


of course, you can probably be quite a bit more efficient by only blending the part of the bitmaps that actually have text on them (use the vertical and horizontal extents of the text to get the rectangle)

[Edited by stigant at Local Time:03-26-2005 at 02:08 AM]

____________________________
Progress Quest Progress
03-26-2005 at 01:59 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
bradwall
Level: Smiter
Avatar
Rank Points: 423
Registered: 02-12-2003
IP: Logged
icon Re: Java and Alpha Blending (0)  
I would be drawing straight to the screen.
Thanks for the information... it gives me some good ideas to play with.

03-28-2005 at 04:28 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
New Topic New Poll Post Reply
Caravel Forum : Other Boards : Anything : Java and Alpha Blending
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.