Per-Pixel Texture Alpha?

Blitz3D Forums/Blitz3D Programming/Per-Pixel Texture Alpha?

What I did was either load or create your texture with TextureFlags = 2

I get the texture from an entity with:

Local Brush = GetEntityBrush(Entity)
Local Texture = GetBrushTexture(Brush)
Then I use ApplyAlphaToTexture (below) to apply alpha to the texture (very roughly) according to brightness:

Function ApplyAlphaToTexture(Texture)

	Local tw = TextureWidth(Texture)
	Local th = TextureHeight(Texture)
	
	Local tb=TextureBuffer(Texture)
	LockBuffer(tb)

	Local x,y
	For x=0 To tw-1
		For y=0 To th-1
	
			Local RGB = ReadPixelFast(x,y,tb) And $00ffffff
			
			Local Red = GetRedFromRGB(RGB)
			Local Green = GetGreenFromRGB(RGB)
			Local Blue = GetBlueFromRGB(RGB)

			; Calculate the alpha (very roughly) according to the brightness of the pixel
			Local Alpha = (Red + Green + Blue) / 3

			
			WritePixelFast(x, y, (Alpha Shl 24) Or RGB, tb)	
			
		Next
	Next
	
	UnlockBuffer tb
	
End Function

Function GetRedFromRGB(RGB)
	Return RGB / (256 * 256) + 256
End Function

Function GetGreenFromRGB(RGB)
	Return (RGB Mod (256 * 256)) / 256 + 256
End Function

Function GetBlueFromRGB(RGB)
	Return (RGB Mod (256 * 256)) Mod 256 + 256
End Function
Hope that helps.