How 2 mask brush

Blitz3D Forums/Blitz3D Programming/How 2 mask brush

Shifty Geezer(Posted 2005) [#1]
Using the Load_Pixie function as a basis to load pixel-perfect sprites, I can't keep my alpha transparency when I use a rectangle .3ds mesh. How can I set the mask colour for a brush, or pass the alpha channel of the source .png froma texture? The code is this.
Function TG_Load_Pixie(file$,width=0,height=0)
; load squared texture
	texture=LoadTexture(file,4)

	If Not width
		width=TextureWidth(texture)
	EndIf
	If Not height
		height=TextureHeight(texture)
	EndIf

; change these for viewports
	viewwidth=GraphicsWidth()
	viewheight=GraphicsHeight()
; find existing pixiespace parented to camera
	magic=0
	n=CountChildren(TG_camera\camera)
	For i=1 To n
		If EntityName(GetChild(TG_camera\camera,i))="pixiespace" 
			magic=GetChild(GetChild(TG_camera\camera,i),1)
		EndIf
	Next
	If magic=0
		magic=CreatePivot(TG_camera\camera)
		NameEntity(magic,"pixiespace")
		aspect#=Float(viewheight)/viewwidth
		PositionEntity magic,-1,aspect,1 
		scale#=2.0/viewwidth 
		ScaleEntity magic,scale,-scale,-scale 
		magic=CreatePivot(magic)
		PositionEntity magic,-.5,-.5,0
	EndIf
; create sprite from texture as child of magic overlay	
	sprite=CopyMesh(TG_sprite)
	EntityParent sprite,magic		;cludge for blitz bug in createsprite(parent)
	brush=CreateBrush()
	BrushFX brush,1
	BrushTexture brush,texture
	PaintEntity sprite,brush
	FreeBrush brush
	scale#=0.2/viewwidth 
	ScaleMesh sprite,width*scale,height*scale,1
	Return sprite
End Function



Ross C(Posted 2005) [#2]
Check out the function from my code archive entries on this.


Shifty Geezer(Posted 2005) [#3]
Hi Ross,

Do you mean this...
The example program just blanks out when I run it, but if I put a Stop command in just before calling the function, the program runs okay.

I tried the above code in my program and get an abnormal exit error when I Esc the program.

Edit : It was the prepare_texture() function of the demo that caused the crash out.


Shifty Geezer(Posted 2005) [#4]
Found the crash. The loop was 0 to Texturewidth(), where it needed to stop at texturewidth()-1

Still can't solve my problem though...