Partly Transparent Sprites

Blitz3D Forums/Blitz3D Programming/Partly Transparent Sprites

PoliteProgrammer(Posted 2006) [#1]
Hi All!

Okay, I've got 3 things - a sprite, a texture and an image. I've made the texture the same size as the image. The image has the background colour masked.

I open the texturebuffer for that texture and draw the image to it, however the background of the image when applied to the texture is not transparent.


Does anyone have a better way of allowing me to draw a certain image to a texture, while making the background of it transparent?


b32(Posted 2006) [#2]
I think the image you are drawing onto the texture is transparent, but the texture itself isn't.
If you are using CreateTexture, the masked/alpha flags don't work. There is a workaround for it, but I forgot which one, look a bit at previous topics. A very lousy workaround is saving the image, then loading the file as a texture with the right transparency flags. With textures, the transparent color is allways black.


Subirenihil(Posted 2006) [#3]
DrawImage does not use the transparent color when drawing to a texture.

A workaround that works in realtime (if your not doing this for lots of textures) is to draw the image to another image that is the same size as the texture. Then CopyRect that image to the texture.

If you want the image to draw transparency to the texture, then you have 2 options:
1) if the texture is to be either solid color or totally invisible - no half see-through - you can use texture flag 4 (masked) and have the ImageMask <image>,0,0,0
2) if you want parts of the texture to be partially transparent then you're going to need LockBuffer, ReadPixelFast, WritePixelFast, and UnlockBuffer


jfk EO-11110(Posted 2006) [#4]
BTW recently it turned out that there are a few machines that will MAV when you try to do drawing operations directly on a texturebuffer (as seen with the Oval command). THerefor I'd suggest to draw to the backbuffer and then copyrect to the texturebuffer, and never ever draw to the texturebuffer directly.

BTW to set the transparency of a texture you will have to set the alpha channel manually, even if you used to copy black pixels to a masked texture. The transparency of black texels is only set autmaticly if you load a texture with the flag 4, contrary to a created texture.

This may be useful for you:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1806


AJirenius(Posted 2006) [#5]
Subirenihil helped me out with this very similar issue in this thread: http://www.blitzbasic.com/Community/posts.php?topic=64678

It has code and everything, also a screen of the result.