views:

115

answers:

2

I'll describe my overall goal in case the question I asked isn't in the best form to get the answer I'm looking for. I have a sphere of words or "word ball" that spins around the X axis. As words spin to the back (Z coordinate goes from -1 to 1, front to back), I intend to change the size and the opacity of each word so that words in "front" are 100% opaque and full-sized and words in back are smaller and somewhat transparent. I would prefer to do this with straight Delphi code and avoid things like Direct3D, etc. I already have the rotation code working fine. I just need to implement my Z coordinate based perceptual shading idea.

When I create the word ball I dynamically create a TImage component for each word. I "print" the word to the TImage bitmap using the TCanvas.TextOut() method in a centered manner. I intend to use BitBlt to copy that bitmap to the correct location in the main Canvas that holds the word ball, because BitBlt is fast and can resize bitmaps on-the-fly, meeting one of the requirements for my perceptual shading operation.

But I don't know the best way to facilitate the Alpha blending. I know that Windows has the AlphaBlend() call and it seems fairly straightforward to use. But I would need to know how to create a bitmap that is a copy of the per-word TImage component that has an alpha channel. Note, in my case the entire bitmap will have a uniform value for the alpha channel since I want the opacity to be applied uniformly to the entire word, based on it's Z coordinate.

Does a dynamically created TImage component with a bitmap made by using TCanvas.TextOut() have an Alpha channel? If not, how do I create one, or create a copy of a TImage bitmap in real time that does have an Alpha channel to be passed to the AlphaBlend() call? If there's a better way to do all this just let me know.

+1  A: 

The documentation says:

The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantaAlpha value is combined with any per-pixel alpha values. If SourceConstantaAlpha is 0, it is assumed that the image is transparent. Set the SourceConstantaAlpha value to 255 (which indicates that the image is opaque) when you only want to use per-pixel alpha values.

So I guess your image doesn't have to be in any special format if you just want a whole image constant transparency.

On the other hand, I don't think that's what you want. Just imagine one rectangular area with text overlapping with another: although some parts of the rectangle might not have text, they'll still be drawn in a semi-transparent white, or whatever one you have as background, color.

himself
+1  A: 

I found this link that gives a solid example of how to do Alpha Blending in Delphi 6 and now I have it working:

http://www.delphi-central.com/tutorials/AlphaBlend.aspx

It's very close to using BitBlt() or StretchBlt() parameter-wise, except for the last parameter which is the alpha-blend structure and is very easy to understand. Combine that with the comment by "himself" above and you have all you need to do Alpha blending.

Robert Oschler