Textures containing transparent sections

Blitz3D Forums/Blitz3D Programming/Textures containing transparent sections

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

First - there are two Transparency Modes for Textures: Mask and Alpha.

You have to define this as the Textureflag, 4 for Mask or 2 for Alpha.

tex=createtexture(64,64,2 or 1)
so it's Alpha as well as fullright.

With Mask you only have the choice of opaque(non-black) or fully transparent(black). With alpha the Brightness of the Pixel will define its tranparency, the darker, the more transparent, UNLESS you load a Texture with a predefined Alpha-Channel such as a 32 Bit TGA Picture.

However, you can manipulate the Alpha-Channel of a Texture in Memory whenever you like this way:

setbuffer texturebuffer(tex)
lockbuffer
for j=0 to textureheight(tex)-1
 for i=0 to texturewidth(tex)-1
  rgb=readpixelfast(i,j) and $FFFFFF
  ;  example of semitransparence for black parts:
  if rgb=0 ; black
   argb=(127 shl 24) or rgb ; using 127 for alphabyte
  else
   argb=rgb ; alphabyte remains zero
  endif
  writepixelfast i,j,argb
 next
next
unlockbuffer
setbuffer backbuffer()


Please note, that unlike Maskmode the Alphamode sometimes makes Problems with the Z-Order of the Objects, especially if they have intersecting parts.