Semi-transparent image?

Blitz3D Forums/Blitz3D Beginners Area/Semi-transparent image?

Terry B.(Posted 2007) [#1]
How would you make part of an image semi-transparent in 2d?
Meaning like you can see the image(meaning maskimage wont work), but you can also see whats under it. I need to use it for a glow effect, because I have a glowing bullet, and the glow outline around it shows, and blocks out the background(which looks weird) How would I make it so that you can see the glow but also the background?


b32(Posted 2007) [#2]
In 3D, I suppose. I'm not sure if you can use 2D images with 'alpha'. However, using 3D to simulate 2D should work.


Terry B.(Posted 2007) [#3]
Hmm, I really need it to be 2d. But thanks anyway.

I heard somwhere that one of the image formats support alpha. Anyone know if thats true and if so which one?


Stevie G(Posted 2007) [#4]
PNG and TGA support alpha but the alpha bits are not used for 2d images. You'll need to use textures unless there is a 3d party library out there.


elcoo(Posted 2007) [#5]
I'm not sure, but i think, if you make a .bmp file, the black parts of the image are invisible. I made something like a glow effect to, and it worked fine.


Matty(Posted 2007) [#6]
In 2d if you are trying to perform alpha blending (transparency) then you will need to use the writepixelfast/readpixelfast commands - first read the background image's pixel color components (it may be stored in a bank or array for a reasonable speed increase), read the pixel color of the pixel in the image you want to alpha blend, calculate the new red/green/blue components values based on these figures and the alpha value for the pixel (this could also be all stored in an array or bank for a reasonable speed increase) then you will need to draw the resulting pixel with writepixelfast.

This obviously means you have to iterate through all the pixels in the image - however one way you can optimise it by not performing the calculation for pixels which are completely transparent or completely opaque.

something like this :

(I may have taken some of this from the code archives a long time ago, it is very useful)
RGB=readpixelfast(x,y,imagebuffer(your image handle goes here))
BRGB=readpixelfast(x,y,backbuffer()) ;background rgb value
Alpha#=0.5 ;for example 50% transparent.
;if you want each pixel to have its own Alpha value you will need to store this yourself as blitz3d/blitzplus in 2d cannot read the alpha values using the readpixel commands, however you can store them in a bank by either creating your own image format or by obtaining the alpha values from the image files directly when loading
		
bR = (BRGB Shr 16) And 255
bG = (BRGB Shr 8 ) And 255
bB = (BRGB       ) And 255
dR = Float(((RGB Shr 16) And 255) - bR)*Alpha#  
dG = Float(((RGB Shr 8 ) And 255) - bG)*Alpha#
dB = Float(((RGB       ) And 255) - bB)*Alpha#
RGB=((bR+dR) Shl 16) Or ((bG+dG) Shl 8) Or (bB+dB)
				
writepixelfast x,y,RGB,backbuffer()



Something like that should get you started..


Jerome Squalor(Posted 2007) [#7]
you can also make some of the pixels black
(mask color) so that you can see through it