Texture alpha

Blitz3D Forums/Blitz3D Programming/Texture alpha

AbbaRue(Posted 2004) [#1]
I am trying to create a texture with all black pixels Alpha. But can't seem to get it to work.
Here is my code.

ts=512
tex55=CreateTexture (ts,ts,15)
SetBuffer TextureBuffer (tex55,0)
For cdy= 0 To ts-1
For cdx= 0 To ts-1
rcg=Rnd(0,100)
If rcg<70 Then rcg=0
rcr=Int(rcg/2)
rcb=Int(rcg/4)
Color rcr,rcg,rcb
Plot cdx,cdy
Next
Next

ClearTextureFilters
TextureFilter "",15

From what I read this should have worked. But the black always comes out black, not transparant.
I added the TextureFilter part after to see if that would help.
But by theory it should have been set by CreateTexture (ts,ts,15).
CreateTexture doesn't seem to work right.
Also tried:
TextureBlend tex55,1
No success.


Floyd(Posted 2004) [#2]
Plot is a 2d (DirectDraw) command. It always writes an alpha value of 255, which means fully opaque.

You need to use WritePixel on the Texture to control alpha in addition to r,g,b.


jfk EO-11110(Posted 2004) [#3]
ploting does not set the alpha value, this works only for loaded alpha maps. You better use WritePixel and use the most significant byte as alpha value:

; 0 to 255
red=100
green=150
blue=255
alpha=200
rgb=(red shl 16) or (green shl 8) or (blue)
WritePixel x,y rgb or (alpha shl 24)

Of course, you could also say
rgb=$FF33FF ; Hex Color, just like in HTML

and then use Readpixelfast with Lockbuffer to make it faster.

BTW if you use a Texture Filter Flag of 15, this will include Flag 2 as well as Flag 4 - I am not sure if you can use both at the same time, I think you can't. So better use 11.


AbbaRue(Posted 2004) [#4]
So how would I rewrite the preveous example to work with WritePixel.
I'm not sure how to set the buffer of "WritePixel" .
And yes 15 does work right I use it for loaded textures.
All my loaded textures are set to either 15 or 9. Depending if I want alpha or solid textures.
At least with my graphics card, it does.
And thanks for telling me about Plot.


AbbaRue(Posted 2004) [#5]
Finally I have an Alpha Tile.
For anyone that needs Random tile for tree leaves, here is the code.


ts=512
tex55=CreateTexture (ts,ts,15)
SetBuffer TextureBuffer (tex55,0)
For cdy= 0 To ts-1
For cdx= 0 To ts-1
rca=255 ;alpha
rcg=Rnd(0,150) ;green
rcr=Int(rcg/2) ;red
rcb=Int (rcg/4) ;blue
argb=0 ;clear color
argb=(rca Shl 24) Or (rcr Shl 16) Or (rcg Shl 8) Or (rcb)
If rcg<74 Then argb=0 ;just to be sure lots of black
WritePixel cdx,cdy,argb

Next
Next

SetBuffer BackBuffer() ;back to screen

Thanks for the help. Hope someone else can use this too.