Alpha blend with fonts

BlitzMax Forums/BlitzMax Programming/Alpha blend with fonts

Pengwin(Posted 2010) [#1]
I am at my wits end with a little problem right now. I am hoping that someone here may be able to spot what I am missing.

I have a text effect that appears on the screen. It should fade out, whilst growing bigger. I am seeing the growing of the text on screen, but the alpha blending does not seem to work. I have posted the class that does this below, could one of you gurus have a look and see what I am missing?

Whilst this effect is in effect (excuse the expression), the main program loop calls the Update method and then the DoDraw method.
I have used an array of image fonts to speed up the growing of the text (these fonts are stored as global variables)

The blend mode has been set to ALHPABLEND before calling the DrawTo method.
Type TextInstance Extends EffectInstance
	Field Size:Int=0
	Field _text:String
	Field Alpha:Float=1.0
		
	Method Update:Int()
		Size:+1
		If Size>10 Then Size=10
		Alpha:-.01
		If Alpha<0.0 Then Alpha=0.0
		TimeLeft:-1
		Return TimeLeft<=0
	End Method
	
	Method DoDraw(X:Int , Y:Int)
		SetAlpha(Alpha)
		SetColor(255,255,0)
		SetImageFont(EffectFont[Size])
		Local th:Int=TextHeight(_text)
		Local tw:Int=TextWidth(_text)
		DrawText(_text,x-(tw/2),y-(th/2))
	End Method
	
	Method Kill()
'
	End Method
	
	Function Create:TextInstance(x:Int , y:Int, Text:String)
		Local o:TextInstance = New TextInstance
		o.WorldCoordinates=False
		o.x = x
		o.y = y
		o._text=Text
		o.TimeLeft = 128
		Return o
	End Function
			
End Type


Last edited 2010


Grey Alien(Posted 2010) [#2]
Change the mode the ALPHABLEND just before DrawText() as a test, to make sure it isn't getting reset somewhere else (happens to me sometimes).

Also did you load the font with the correct flags (smoothfont I think it's called)? Without that, it won't have nice edges when scaled.


Pengwin(Posted 2010) [#3]
Thanks for the reply, Jake.

I changed the DrawTo method to

	Method DoDraw(X:Int , Y:Int)
		SetColor(255,255,0)
		SetImageFont(EffectFont[Size])
		Local th:Int=TextHeight(_text)
		Local tw:Int=TextWidth(_text)
		SetBlend ALPHABLEND
		SetAlpha Alpha 		
		DrawText(_text,x-(tw/2),y-(th/2))
	End Method


But there was no difference.


Pengwin(Posted 2010) [#4]
I feel like such an idiot!! I found the issue.

I copied this effect from another effect in the game, unfortunately I forgot to change the main initialiser, which generated about 30 instances. therefore, I was getting the same text overlaid 30 times, negating the alpha blend effect.

That'll teach me for pulling an all nighter!!!


Grey Alien(Posted 2010) [#5]
It happens to us all.