Maskimage for textures?

Blitz3D Forums/Blitz3D Programming/Maskimage for textures?

Craig H. Nisbet(Posted 2004) [#1]
I know that you can have a entity use mask mode to not render the black portions of the it's texture, but is there a way to make it use another color othere then black as it's mask color?


jfk EO-11110(Posted 2004) [#2]
you can write your own texture masking function easily.

eg:
function MaskTexture(tex,r,g,b)
 setbuffer texturebuffer(tex)
 lockbuffer()
 for j=0 to textureheight(tex)-1
  for i=0 to texturewidth(tex)-1
   rgb=readpixelfast(i,j) and $FFFFFF
   r2=rgb shr 16
   g2=(rgb shr 8) and $FF
   b2=rgb and $FF
   if (r=r2) and (g=g2) and (b=b2)
    alpha=0
   else
    alpha=$FF ;(=255)
   endif
   writepixelfast i,j,(alpha shl 24) or rgb
  next
 next
 unlockbuffer()
 setbuffer backbuffer()
end function

(not tested, just out of my head)

of course, instead of checking for exact matching you can also use a color range, or a certain brightness range, or only the blue tone, or whatever.