setalpha

BlitzMax Forums/BlitzMax Beginners Area/setalpha

*(Posted 2005) [#1]
how do you use setalpha?

ive tried using the alphablend thing but everything goes funny coloured and slow, is there any way to use it for realtime stuff?


tonyg(Posted 2005) [#2]
Have you got any example code as it works in realtime for me OK. Basically,
setblend alphablend
setalpha 0.8
Have you tried by gl and dx drivers?


*(Posted 2005) [#3]
nah will have a look, been trying to get it to work in me game unfortunately its rather large :D


tonyg(Posted 2005) [#4]
I don't quite get what you're asking for.
This is an example of using alphablend...
Graphics 640,480
image=LoadImage("max.png")
SetClsColor 100,100,100
alpha#=0.8
While Not KeyHit(key_escape)
   Cls
   SetBlend alphablend
   SetAlpha alpha
   DrawImage image,MouseX(),MouseY()
   If KeyHit(key_up) alpha=alpha+0.1
   If KeyHit(key_down) alpha=alpha-0.1
   Flip
Wend
End

but I'm sure you could have tested that it works OK in that situation.


ImaginaryHuman(Posted 2005) [#5]
The alpha value ranges from 0.0 to 1.0 for each pixel.

If you use SetAlpha 0.5, then any alpha values in your image that are brighter than `half` will determine which pixels are masked in/out when using it for SetBlend MASKEDBLEND. Usually, pixels in your alpha channel will be either 1.0 or 0, where 1.0 means include the pixel and 0 means exclude it, so by setting the value at 0.5 (the default) it would only include the 1.0 pixels.

You can set the level higher or lower so that you mask in/out different levels of color. You could effectively have a loop ranging from 0 to 0.5 or whatever which would gradually dissolve the image in.


*(Posted 2005) [#6]
as an idea wouldnt it be better to internally set Alphablend within setalpha when the value is below 1.0 and use maskedblend if the alpha value is at 1.0. Would save all the Blendmode silliness.


Dreamora(Posted 2005) [#7]
wouldn't be of any use. You have to set the blend before drawing the image so there is no use if it has been set "hours" before while it has been set to other blendmodes before.


ImaginaryHuman(Posted 2005) [#8]
It would be faster to do a solidblend but probably not a masked blend as masking actually uses the same kind of code, modes and tests that alpha blending using.