This topic is now archived and is closed to further replies.


[java] Alpha blending?

Recommended Posts

Arch@on    100
So... I decided to make transparent/opague dialog screen to my game(rpg) and I found out serveral ways to do it. Firstly there was classic way to draw gif which has every second pixel transparent. As you can quess it''s slow and it isn''t definetly way to do it. Second way is alpa blending, but I have no clue how can I make opaque picture. Let''s say that I want to mask my map with screen so that the map is behind that screen mask and it still show. Right now I can''t remember right words to describe it... Time comes, time goes and I only am.

Share this post

Link to post
Share on other sites
Jerry Lynn    122
To make your partialy opaque picture I would think you would just set the part of the map ''mask'' that is see-through as transparent color - just the inverse of a typical ''sprite'' where the ''center'' part is visible and sourrounded by a transparent color.

How you would accomplish an alpha blended blt of a graphic with variable levels of transparency to the screen would depend on what API you were programming against (DirectX, some version of OPENGL, Java 2D or 3D).

Assuming you are programming in pure Java with no 3D extensions you would use the AlphaComposite class.

Here is a reference on the topic that I found...

A little quote from that reference:

"The AlphaComposite class provides a default implementation of the Composite interface. AlphaComposite supports the blending of new pixel data with existing pixel data using alpha color values in the new and existing pixel data. The alpha color values identify the transparency of a color using a scale of 0.0 to 1.0. If a value of 1.0 is used, the new pixel data completely replaces existing pixel data. If a value of 0.0 is used, any existing pixel data is used instead of new pixel data. If a number between 0.0 and 1.0 is used, the new and existing pixel data are used in proportion to this value. For example, a value of 0.6 causes the color of the new pixel data to contribute 60% of the value of the composite color and the existing pixel data to contribute 40% of the value. In addition to the alpha values of the new and existing pixel data, a separate alpha scale factor may also be specified. This scale factor ranges from 0.0 to 1.0 and is multiplied by the alpha values of the new and existing colors. In addition to this scale factor, the AlphaComposite class provides additional compositing rules. These rules are implemented as class constants and may be used to specify a particular compositing approach."

Share this post

Link to post
Share on other sites