CreateTexture mask

Blitz3D Forums/Blitz3D Programming/CreateTexture mask

Boiled Sweets(Posted 2006) [#1]
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?


kevin8084(Posted 2006) [#2]
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()



Boiled Sweets(Posted 2006) [#3]
Yeah...

ClsColor 0,0,0
Cls


kevin8084(Posted 2006) [#4]
LOL...reply while I was editing. Other than that, the only thing that I can think of is a palette issue.


kevin8084(Posted 2006) [#5]
Actually, isn't masking done in 32 bit? Is your display and program set to 32 bit?


Bobysait(Posted 2006) [#6]
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")




kevin8084(Posted 2006) [#7]
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



Boiled Sweets(Posted 2006) [#8]
Methinks this is a bug!


kevin8084(Posted 2006) [#9]
Yeah, I've been experimenting with the masking and can't seem to get it to work properly.


GfK(Posted 2006) [#10]
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.


Boiled Sweets(Posted 2006) [#11]
Gfk,

well it does but hardly an elegant solution. Shouldn't BRL fix this?


big10p(Posted 2006) [#12]
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)



kevin8084(Posted 2006) [#13]
Or, you could do as GfK said, for example:



jfk EO-11110(Posted 2006) [#14]
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