Can I create an alpha channelled texture in code?

Blitz3D Forums/Blitz3D Programming/Can I create an alpha channelled texture in code?

Yes, you can.

If you want to use a rendered image to create it from it's a good idea if you render twice. Once in normal color, and once where the model is completely white (on a black background) to get an alpha channel from.

You cannot copy it directly over to the texture, so you have to use readpixel/writepixel to generate the alpha channel.

The steps are these:
1: CreateTexture of proper size and with the Alpha flag set
2: Render normal model
3: Render completely white model on black background
4: For every pixel in the texture
5: rgb = ReadPixel from normal render
6: a = ReadPixel from b/w render
7: argb= blue Or (green Shl 8) Or (red Shl 16) Or (alpha Shl 24)
8: WritePixel x,y,argb,to the texture
9: Repeat from 5 until done