Manual additions to texture buffer are masked out?

Blitz3D Forums/Blitz3D Programming/Manual additions to texture buffer are masked out?

taxlerendiosk(Posted 2004) [#1]
I'm trying to overlay a 2-colour PNG image over a JPEG texture so that the mask is correct (JPEG messes it up, of course). However, the image drawn over the texture seems to have ALL its pixels set to the mask colour, or zero alpha if I use that instead (so invariably it just makes a rectangular "hole"). The same thing happens with the TextureBuffer demo, if I set the flags in the CreateTexture line to 2 or 4, the text disappears. Is this correct behaviour, or a problem with my card or Blitz or something? I have the latest Blitz3D update installed.


fredborg(Posted 2004) [#2]
You actually need to set the alpha channel on masked textures to make the mask. So you need to use readpixelfast and writepixelfast, to get it to work.
Graphics3D 640,480,0,2
SetBuffer BackBuffer()

tex = CreateTexture(256,256,1+4)

For x = 0 To 255
	For y = 0 To 255
		red = Abs(127.5-x)*2
		grn = Abs(127.5-y)*2
		blu = 100
		alp = ((y + x) Mod 64)*4
		WritePixel x,y,(alp Shl 24) + (red Shl 16) + (grn Shl 8) + blu,TextureBuffer(tex)
	Next
Next

font = LoadFont("arial",35)
SetFont font
Text 128,128,"HELLO WORLD",True,True
FreeFont font

For x = 0 To 255
	For y = 0 To 255
		If ReadPixel(x,y,BackBuffer()) = -1
			red = 255
			grn = 255
			blu = 255
			alp = 255
			WritePixel x,y,(alp Shl 24) + (red Shl 16) + (grn Shl 8) + blu,TextureBuffer(tex)
		EndIf
	Next
Next

cube = CreateSphere(32)
EntityTexture cube,tex
EntityFX cube,1+16

camera = CreateCamera()
PositionEntity camera,0,0,-3

Repeat
	
	TurnEntity cube,0,-1,0
	
	RenderWorld
	Flip

Until KeyHit(1)



Ross C(Posted 2004) [#3]
*nod*

also here for the function version

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013


taxlerendiosk(Posted 2004) [#4]
Thanks a lot! Makes sense now.