Maskblend Vs Alphablend

BlitzMax Forums/BlitzMax Beginners Area/Maskblend Vs Alphablend

tonyg(Posted 2005) [#1]
What's the difference between Maskblend and Alphablend with setalpha 1.0?
Doing the latter means you can alpha an image simply by changing the setalpha back and forward rather than switching maskblend and seems a bit quicker.
Not entirely sure about my test so if anybody can see a problem please let me know...

There are a couple of differences.
The alpha'd image show a few more pixels than the masked image.
On this machine, the maskalpha TESTTWO doesn't show the image as alpha'd.
Finally, if I run JUST TESTTWO it has different debuglog results than running both TESTONE and TESTTWO.
Hope that all makes sense


Dreamora(Posted 2005) [#2]
The difference between the two is:

MaskBlend bases on the mask color (normally black) while AlphaBlend bases on the 4th color component (alpha).

MaskBlend only supports 2 states: "visible" and "invisible"

AlphaBlend can have everything in between (0-255 in 32bit screendepth which is needed for alpha), if the image is PNG / TGA with a saved alpha channel.

This is especially usefull for particles, fake water and similar stuff where you need translucent but still colored surfaces.

You're test only takes vertex alpha into account (SetAlpha does not change the image alpha values but the vertices) which might give quite wrong "benchmarking" results when real alpha textures are used.


tonyg(Posted 2005) [#3]
OK, I understand (most of) that.
So what is the difference between...
setblend maskblend
drawimage image,0,0
and
setblend alphablend
setalpha 1.0
drawimage image,0,0
?
To me it seems they both have maskblend applied and no (or full whatever way around it is) alpha blending.
p.s. Anybody got a real alpha texture image I can test with?


FlameDuck(Posted 2005) [#4]
To me it seems they both have maskblend applied
They might. It depends on how the Image is loaded (AFAIR).

The advantage (or rather one of them) of using alphablended images over masked ones, is the anti-aliased edges can be made partially transparent, so they will blend correctly with the actual background in the game, rather than (say) the background in your paint program.

There are a few real alpha images included in the samples directory of BlitzMAX.


tonyg(Posted 2005) [#5]
Hmm, still confused.
Why doesn't this apply any alphblend to the second image?
Graphics 800,600,0
image:TImage=LoadImage("max.png")
cls
SetBlend maskblend
'setblend alphablend
'setalpha 1.0
DrawImage image,0,0
SetAlpha alphablend
SetAlpha 0.6
DrawImage image,100,0
Flip
WaitKey()

when the alphablend does?


Perturbatio(Posted 2005) [#6]
try SetBlend AlphaBlend instead of SetAlpha AlphaBlend


tonyg(Posted 2005) [#7]
Sod it!. I've been running that test for hours trying to figure out why I was getting an alpha image.
<edit> Now the timings are identical and I feel a prat.
<edit2> Just realised as well that alphablend is a const 3 so it was setting alpha to 3.0 (i.e. 1.0) so I can't even moan it should have thrown an error.


Chris C(Posted 2005) [#8]
yeah but aint that what makes programming rewarding?!
we ALL do it!


Perturbatio(Posted 2005) [#9]
I don't mik mastakes.


tonyg(Posted 2005) [#10]
OK, so now I've recovered.
What *is* the difference between maskblend and alphablend with setalpha 1.0?
All tests I have (correctly) run seem to suggest they're the same thing.
Probably doesn't matter but might save switching
They *do* display images slightly different (e.g the yellow underlining in the blitzmax logo) but doesn't this mean it's better to use one blend all the time and not switch?