texture problem

Blitz3D Forums/Blitz3D Programming/texture problem

D4NM4N(Posted 2005) [#1]
Im trying to create a HUD.
In my last game jetscream, i used a textured plane at 1.1 in front of the camera.
The only way i could make the texture transparent was to use blendmode. The problem with this is its too bright up on very light areas.

What im trying to do now (as i tried before) is use a masked texture. Unfortunately the createtexture(x,y,4) doesnt seem to mask at all, and corrupts all the data in the texture. WHY WHY WHY!! Im using the correct setbuffers etc and works fine for color.

The other way is to use alpha, but how fo i create an alpha channel on an internally created texture?


big10p(Posted 2005) [#2]
The only way I know around this is to manually WritePixelFast the alpha channel to each pixel, before drawing the image onto it. I think you still need to use the mask flag when creating the texture, too.


fall_x(Posted 2005) [#3]
edit : sorry, my answer was irrelevant, so I deleted it.


jfk EO-11110(Posted 2005) [#4]
as soon as you draw something to a texture, the alpha channel get's lost. This will affect msaked as well as alphaed textures.

The best solution that I know is to fix the alpha channel manually. if you update your HUD each frame, it may be too slow. Especially when you wanted to use one big quad that stretches across the entire screen for all the HUD element. Think about to use a set of HUD quads with smaller textures and only update the ones that have been edited.

function fixalpha(tex)
 setbuffer texturebuffer(tex)
 lockbuffer()
 for y=0 to textureheight(tex)-1
  for x=0 to texturewidth(tex)-1
   rgb=readpixelfast(x,y) and $ffffff
;   the next line calculates the brightness of the pixel. this would be the alpha value of a texture when it was loaded with the alpha flag
;   bri=((rgb shr 16)+((rgb shr 8)and $ff)+(rgb and $ff))/3
; an other method is to make everything semitransparent, only the black parts are fully transparent
   if rgb=0 then 
    bri=0
   else
    bri=127
   endif
   argb2=(bri shl 24) or rgb
   writepixelfast x,y,argb2
  next
 next
 unlockbuffer()
 setbuffer backbuffer()
end function



D4NM4N(Posted 2005) [#5]
Cheerz Jfk ill try it