creating masked sprites

Blitz3D Forums/Blitz3D Beginners Area/creating masked sprites

Slomas(Posted 2012) [#1]
I know you can specify a mask (black areas are transparent) when using Loadsprite, but how do I do it if i'm using createsprite() and applying a texture? masking the texture doesn't seem to work?

thanks, Steve


Captain Wicker (crazy hillbilly)(Posted 2012) [#2]
http://www.blitzbasic.com/Community/posts.php?topic=73608
Blitz3D SDK example but same principles apply :)

Try searching the code archives, I always find my answers there! :)
http://www.blitzmax.com/codearcs/codearcs.php

Last edited 2012


Slomas(Posted 2012) [#3]
Thanks- the exmple works for me though ideally I'd like to avoid saving & loading - I'll check the archives


Kryzon(Posted 2012) [#4]
If I'm not mistaken the thing with masking is that it will clear out texels with alpha values below 128 - this as explained in a Code Archive entry by Ross C.

When you load a texture with the MASK flag (4), the internal texture loader goes through the texture buffer and writes 100% alpha values for texels that are colored, and for texels that are black it writes 0% alpha (= transparent).

But that's the catch - this is done by the loader.
If you use CreateTexture(), the texture won't go through this process even if you create it with a MASK flag.

So for every texture you create with CreateTexture(), after filling the texture's buffer with colored content, go through every texel of it and do the same.

Since you're doing this manually you can choose any color you want to be the mask - not just black.
The important thing is setting an alpha value of '0' for these masked pixels, and for all other pixels use FF (255) alpha.
For this to ultimately work you do need to create textures with MASK flags.

Last edited 2012


Ross C(Posted 2012) [#5]
I have a function in the archives that can take a texture and colour mask it:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013