Transparency

Blitz3D Forums/Blitz3D Programming/Transparency

Graythe(Posted 2004) [#1]
Hi,

In order to achieve transparency I usually do a writepixel with &0 to each and every pixel. That can take some time. So, I thought what I'd do was create a small texture (8x8), write each pixel to black and then copyrect that however many times needed to erase large textures.

It certainly sped things up but did not give me transparency. What am I doing wrong?

Graphics3D 640,480,1

Const One%=1,Texture_EraserSize=8

Sprite1=CreateSprite()
Sprite2=CreateSprite()
Sprite1_Texture=CreateTexture(64,64,2)
Sprite2_Texture=CreateTexture(64,64,2)


Repeat
	Choice$=Upper(Input("Mask by Blocks/Pixels (B/P)"))
	Select Choice
		Case "B"
			Initialise_TextureBlocks Sprite1_Texture
			Exit
		Case "P"
			Initialise_TexturePixels Sprite1_Texture
			Exit
	End Select
Forever

White=GetRGB(255,255,255)
SetBuffer TextureBuffer(Sprite2_Texture)
For LoopX=29 To 39
	For LoopY=False To 63 
		WritePixel LoopX,LoopY,White
	Next
Next	
For LoopY=29 To 39
	For LoopX=False To 63
		WritePixel LoopX,LoopY,White
	Next
Next
SetBuffer BackBuffer()

EntityTexture Sprite1,Sprite1_Texture
EntityTexture Sprite2,Sprite2_Texture


CreateCamera()
PositionEntity Sprite1,0,0,5
PositionEntity Sprite2,0,0,6


While Not KeyDown(One)

	RenderWorld
	VWait
	Flip False

Wend
End





Function Initialise_TextureBlocks(TextureNo)
	TextureEraser=CreateTexture(Texture_EraserSize,Texture_EraserSize)
	Initialise_TexturePixels TextureEraser
	NoPels=Texture_EraserSize-One
        XLimit=Texturewidth(TextureNo)-One
	YLimit=Textureheight(TextureNo)-One
        For LoopX=False To XLimit Step Texture_EraserSize
		For LoopY=False To YLimit Step Texture_EraserSize
			CopyRect False,False,NoPels,NoPels,LoopX,LoopY,TextureBuffer(TextureEraser),TextureBuffer(TextureNo)
		Next
	Next
	FreeTexture TextureEraser
End Function


Function Initialise_TexturePixels(TextureNo)
	IHeight=TextureHeight(TextureNo)-One
	IWidth=TextureWidth(TextureNo)-One
	SetBuffer TextureBuffer(TextureNo)
	LockBuffer TextureBuffer(TextureNo)
	For LoopX = False To IWidth
		For LoopY=False To IHeight
			WritePixelFast LoopX,LoopY,False
		Next
	Next
	UnlockBuffer TextureBuffer(TextureNo)
	SetBuffer BackBuffer()
End Function

Function GetRGB%(Red%,Green%,Blue%)
	Return 255 Shl 24 + Red Shl 16 + Green Shl 8 + Blue
End Function



DJWoodgate(Posted 2004) [#2]
Failing to define Xlimit and Ylimit perhaps?


Graythe(Posted 2004) [#3]
Eeek! Cheers DJ, but astonishingly, it still doesn't work.

(I updated the post to include definitions the X & Y limits)


GfK(Posted 2004) [#4]
CopyRect doesn't copy the alpha channel.


Graythe(Posted 2004) [#5]
Aah... thanks GFK. Err ... so is anything that does copy the alpha channel?


DJWoodgate(Posted 2004) [#6]
Copypixel I think. Copyrect will sometimes, it works here in a 32 bit graphics mode.


Dreamora(Posted 2004) [#7]
or readpixelfast / readpixel


Graythe(Posted 2004) [#8]
Well, I can't get the copyrect to work with alpha in any mode . I've tried the drawimage command and the grab command. I still feel that there `must` be a way to do this quickly at run time and without explicitly reddressing each and every pixel. Could we not have a command to either zero the alpha map or copy an alpha map from another texture/image? Hmm? I'll try the feature request thing or whatever it's called today.


Graythe(Posted 2004) [#9]
Oops - that's disappeared as well. Why are things now vanishing faster than small change at a pickpockets convention?


doctorskully(Posted 2004) [#10]
Try locking the buffers & use the ReadPixelFAST/WritePixelFAST commands. It speeds things up quite well for me. Just be careful of course--locked buffers can be tricky. I've locked up Blitz on more than one occasion with those things!


Graythe(Posted 2004) [#11]
Thanks DT, but I have been using the read/write pixelfast commands. Indeed, that much should be evident from the code snippet. No matter.

[Graythe weeps]


Graythe(Posted 2004) [#12]
Ahhh... one uses the DrawBlock command.


Graythe(Posted 2004) [#13]
Weeell, sometimes it works, and sometimes it doesn't. It was working, but now it isn't. Gnash and Gnrr, millenium hand and shrimp!