names of characters over there heads

Blitz3D Forums/Blitz3D Beginners Area/names of characters over there heads

:| I tried doing the two For.. Next loops to write the pixels before but when I did it, I didn't lock the buffers so maybe that's why it didn't work. I changed your masker to make it do exactly what I want, probably faster.

It just fills the texture before you add anything else to it. For some odd reason the text won't show up though but the two rects do.

TextureMaskFill Function
Function TextureMaskFill( texture )
	TW = TextureWidth( texture )
	TH = TextureHeight( texture )
	SetBuffer TextureBuffer( texture )
	LockBuffer 
	For j = 0 To TH - 1
		For i = 0 To TW - 1
			WritePixelFast i , j , 0, TextureBuffer( texture )
		Next
	Next
	UnlockBuffer
	SetBuffer BackBuffer()
End Function


Example
InitGraphics(800,600)

Global Light = CreateLight()
	
Global Camera = CreateCamera()
	PositionEntity Camera,0,2,-5
	RotateEntity Camera,20,0,0

Global Plane = CreatePlane()
	
Global Name$ = "GIA"

Global TurnPivot = CreatePivot()

Global Player = CreateCube(TurnPivot)
	PositionEntity Player,0,1,3
	ScaleEntity Player,.5,.5,.5
	EntityColor Player,255,0,0
	


Global Sprite = CreateSprite()
	ScaleSprite Sprite,.5,.25

Global Sprite2 = CreateQuad(.5,.25,0)
	ScaleMesh Sprite2,-1,1,1
	
Global SpriteTexture = CreateNameTexture(Name,1+2+16+32)
	EntityTexture Sprite,SpriteTexture
	EntityTexture Sprite2,SpriteTexture

EntityParent Sprite,Player
PositionEntity Sprite,1,MeshHeight(Player)/2+.5,0

EntityParent Sprite2,Player
PositionEntity Sprite2,-1,MeshHeight(Player)/2+.5,0

While Not KeyDown(1)
	
	If KeyDown(200) TranslateEntity Camera,0,0,.1
	If KeyDown(208) TranslateEntity Camera,0,0,-.1
	If KeyDown(203) TranslateEntity Camera,-.1,0,0
	If KeyDown(205) TranslateEntity Camera,.1,0,0
	
	TurnEntity TurnPivot,0,1,0
	TurnEntity Sprite2,0,DeltaYaw(Sprite2,Camera)*.8,0
	
	UpdateWorld
	RenderWorld
	
	Flip
	
Wend
End

Function ShadowText(value$,x#,y#,red%=255,green%=255,blue%=255,shadow_red=20,shadow_green=20,shadow_blue=20,center_x=1,center_y=1)
	Color shadow_red,shadow_green,shadow_blue
	Text x+1,y,value,center_x,center_y
	Text x,y+1,value,center_x,center_y
	Text x+1,y+1,value,center_x,center_y
	
	Color red,green,blue
	Text x,y,value,center_x,center_y
End Function

Function InitGraphics(w = 1024, h = 768,title$="Blitz3D Program",exit_message$="")
	Graphics3D w, h, 32, 2
	SetBuffer BackBuffer()
	SeedRnd MilliSecs()
	
	If exit_message <> ""
		AppTitle title,exit_message
			Else
				AppTitle title
	EndIf
End Function

Function CreateNameTexture(name$,flags)
	Local Width% = StringWidth(name)*2
	Local Height% = StringHeight(name)*2
	Local texture = CreateTexture(Width,Height,flags)
	
	TextureMaskFill(texture)
	
	SetBuffer TextureBuffer(texture)
		Color 0,255,0
		Rect 0,0,TextureWidth(texture),TextureHeight(texture)*.1
		Rect 0,TextureHeight(texture)*.9,TextureWidth(texture),TextureHeight(texture)*.1
		
		Color 254,254,0
		Text TextureWidth(texture)*.5,TextureHeight(texture)*.5,name,1,1
		;ShadowText(name,TextureWidth(texture)*.5,TextureHeight(texture)*.5,254)
	SetBuffer BackBuffer()
	
	Return texture
End Function

Function TextureMask( texture , sr=240 , sg=0 , sb=240, st = 30 )
	TW = TextureWidth( texture )
	TH = TextureHeight( texture )
	SetBuffer TextureBuffer( texture )
	LockBuffer 
	For j = 0 To TH - 1
		For i = 0 To TW - 1
			argb = ReadPixelFast( i,j, TextureBuffer( texture ) )
			r = ( argb And $FF0000) Shr 16
			g = ( argb And $FF00 ) Shr 8  
			b = ( argb And $FF )  
			a = ( argb And $FF000000 ) Shr 24
			
			If ( r > sr-st And r < sr+st ) And  ( g > sg-st And g < sg+st ) And ( b > sb-st And b < sb+st )
				
				a = 0 
				r = 0
				g = 0
				b = 0
			Else
				a = 255
			EndIf
			argb = ( a Shl 24 ) Or ( r Shl 16 ) Or ( g Shl 8 ) Or b
			WritePixelFast i , j , argb, TextureBuffer( texture )
		Next
	Next
	UnlockBuffer
	SetBuffer BackBuffer()
End Function

Function TextureMaskFill( texture )
	TW = TextureWidth( texture )
	TH = TextureHeight( texture )
	SetBuffer TextureBuffer( texture )
	LockBuffer 
	For j = 0 To TH - 1
		For i = 0 To TW - 1
			WritePixelFast i , j , 0, TextureBuffer( texture )
		Next
	Next
	UnlockBuffer
	SetBuffer BackBuffer()
End Function

Function CreateQuad(width#,height#,order%=-1,parent%=False)
	Local v0,v1,v2,v3
	Local Point,Surface
	
	If Not parent = False
		Point = CreateMesh(parent)
			Else
				Point = CreateMesh()
	EndIf
	
	If order <> 0
		EntityOrder Point,order
	EndIf
	
	EntityFX Point,1
	
	Surface = CreateSurface(Point)
	
	v0=AddVertex(Surface,-(width*.5),(height*.5),0 ,0,0)
	v1=AddVertex(Surface,(width*.5),(height*.5),0 ,1,0)
	v2=AddVertex(Surface,-(width*.5),-(height*.5),0 ,0,1)
	v3=AddVertex(Surface,(width*.5),-(height*.5),0 ,1,1)
	
	AddTriangle(Surface,v0,v1,v2)
	AddTriangle(Surface,v1,v3,v2)
	
	Return Point
End Function