How to alpha blend 2d in blitz3d

Blitz3D Forums/Blitz3D Programming/How to alpha blend 2d in blitz3d

digideath(Posted March) [#1]
I'm sorry if i'm missing the obvious but is there a way to alpha blend a 2d image in blitz3d? By that I mean make it semi transparent so that the gfx behind show through. Older versions of blitz used to have setblend/setapha for this but blitz3d doesn't recognise those commands.


Matty(Posted March) [#2]
Two ways:

If you are using 2d in 3d using the 3d commands and textured quads simply set the alpha level of the pixels using the writepixel commands or the entityalpha command on the quad itself. However if it is a single surface system then you won't be able to use entityalpha and will instead need to set the alpha of individual vertices of the quads.

If you are using standard 2d then the only way is to use readpixelfast and writepixelfast to calculate a new color for each pixel being tested against the background/other pixels.


skidracer(Posted March) [#3]
I wrote one of those back in the day.

code archive #27


RemiD(Posted March) [#4]
You can do it by using 2 textured quads, and set the zorder of the quads so that you have one on top of the other (using entityorder)
for the blend mode, you have the choice between alpha, multiply, add, more info here :
http://www.blitzbasic.com/b3ddocs/command.php?name=TextureBlend
http://www.blitzbasic.com/b3ddocs/command.php?name=BrushBlend
http://www.blitzbasic.com/b3ddocs/command.php?name=EntityBlend
note that the blend mode of the texture (using textureblend) and the blend mode of the mesh/surface (using entityblend/brushblend) are different things and can be combined to produce different results...
to create a "screen mesh" (a quad which covers the entire screen with a texture which has a texel size same has the pixel size of the screen), see : http://www.blitzbasic.com/codearcs/codearcs.php?code=3256


digideath(Posted March) [#5]
Thanks for the replies and suggestions . Sorry I took a while to get back, was working. Skid, I just stole your function. I hope you don't mind. It saves me the time of knocking it together myself.

Fyi i'm probably using the wrong version of blitz because I am working on a 2d project (a uk style fruit machine simulator). I'm working 2d for this one but I've wrote them in 3d before and am only trying to remind myself of the language atm before delving in too deep. I wrote many games including fruit machine simulators over the years. The first ones I ever wrote were on the amiga 500+ using the original blitz basic so this brings back memories :)