CreateTexture mask
Blitz3D Forums/Blitz3D Programming/CreateTexture mask
| ||
I have created a texture with CreateTexture(256,256,4) and draw dots on it then apply to a mesh. The masking doesn't seem to work, i.e I can see the black background. Any thoughts? |
| ||
are you clearing the texture 0,0,0? Example:tex=CreateTexture(256,256,4) setbuffer texturebuffer(tex) clscolor 0,0,0 cls ; ***edit*** ...put dot routine here setbuffer backbuffer() |
| ||
Yeah... ClsColor 0,0,0 Cls |
| ||
LOL...reply while I was editing. Other than that, the only thing that I can think of is a palette issue. |
| ||
Actually, isn't masking done in 32 bit? Is your display and program set to 32 bit? |
| ||
I have ever try anything to do the mask work correctly with createxture, but ... never arrived. The only solution i have found is : Size=256 Tex=CreateTexture(Size,Size) CurBuffer = Graphicsbuffer() setbuffer texturebuffer(tex) [...] setbuffer CurBuffer saveBuffer (texturebuffer,"TempTexture.bmp") freetexture tex tex=loadtexture("TempTexture.bmp",5) deletefile ("TempTexture.bmp") |
| ||
I got it to work with loading a texture too...the closest I could get it to work with creating a masked texture was to clscolor 255,255,255 |
| ||
Methinks this is a bug! |
| ||
Yeah, I've been experimenting with the masking and can't seem to get it to work properly. |
| ||
This has been an issue in BB3D for as long as I can remember. IIRC, if you draw dots onto your texture, save it, then reload it, it *should* work. I realise this probably doesn't solve your problem, though. |
| ||
Gfk, well it does but hardly an elegant solution. Shouldn't BRL fix this? |
| ||
Yep, this issue has been around forever. You can get around it by using this code before drawing to the texture: tex = CreateTexture(256,256,5) LockBuffer TextureBuffer(tex) For y = 0 To 255 For x = 0 To 255 WritePixelFast x,y,0,TextureBuffer(tex) Next Next UnlockBuffer TextureBuffer(tex) |
| ||
Or, you could do as GfK said, for example: |
| ||
if you are using drawing commands on a texture buffer, alpha channel information will be lost. It is however a good idea to touch up the alpha channel information manually to prevent black edges due to texture filtering: if a texel is black (assuming this should be transparent!) then -Read the rgb of all surrounding texels that are not transparent as well. -Calcualte the average RGB of them, then set the transparent center texel this way: alpha=0 argb= (average_rgb and $FFFFFF) or (alpha shl 24) endif this way the edges of the masked parts will fade to a color that makes more sense than black. EDIT: I just posted an example in the archives: http://www.blitzbasic.com/codearcs/codearcs.php?code=1806 |