ImageFont Glyph Positioning Problem

BlitzMax Forums/BlitzMax Beginners Area/ImageFont Glyph Positioning Problem

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Hi,

I´ve got a problem with TImageFont. I wrote a function that takes an image:TImage, a font:TImageFont and a given text:String and puts the text on the image. (It´s for variable ingame buttons). And because my image has also Alpha, I need to perform everything through Readpixel / Writepixel.

Currently I go into the ImageFont and take the different Glyphs as Images to render them on my button. But the positions of the Glyphs are wrong somehow.

Does anybody know how I get the offsets of the Glyphs?

My code:

Function RenderButton:TImage(button:TImage,font:TImageFont,text:String)
	SetImageFont font
	Local map:TPixmap = LockImage(button)
	
	Local textposx:Int = (button.width - TextWidth(text))/2
	Local textposy:Int = (button.height - TextHeight(text))/2
	Local x:Int
	
	For Local i:Int = 0 Until text.length
		Local n:Int = font.CharToGlyph(text[i])
		If n<0 Continue
		
		Local glyph:TImageGlyph=font.LoadGlyph(n)
		Local image:TImage=glyph._image
			
		If image
			Local frame:TImageFrame=image.Frame(0)
			If frame		
				'frame.Draw 0,0,image.width,image.height,x+tx,y+ty
				'Auf den eigendlichen Button rendern
				Local map2:TPixmap = LockImage(image,0,1,0)
				For Local x0:Int=0 Until image.width
				For Local x1:Int=0 Until image.height
				
					Local px0:Int = x0+x+textposx+glyph._x
					Local px1:Int = x1+textposy+glyph._y
					
					If px0>0 And px1>0 And px0<button.width And px1<button.height 'Secure against buffer overrun
						Local c1:Int = ReadPixel(map2,x0,x1)
						Local c2:Int = ReadPixel(map,px0,px1)
	
						Local a1:Int=c1 Shr 24
						Local rgb1:Long = (c1 Shl 8) Shr 8
						
						Local a2:Int=c2 Shr 24
						Local rgb2:Long= (c2 Shl 8) Shr 8
	
						Local r1:Int=((c1 Shl 8) Shr 8)/$10000
						Local g1:Int=((c1 Shl 16) Shr 16)/$100
						Local b1:Int=((c1 Shl 24) Shr 24)
			
						Local r2:Int=((c2 Shl 8) Shr 8)/$10000
						Local g2:Int=((c2 Shl 16) Shr 16)/$100
						Local b2:Int=((c2 Shl 24) Shr 24)
						
						Local r3:Int=((a1*r1) + (255-a1)*r2)/255
						Local g3:Int=((a1*g1) + (255-a1)*g2)/255
						Local b3:Int=((a1*b1) + (255-a1)*b2)/255
						
						Local c3:Int = a2*$1000000 + r3*$10000 + g3*$100 + b3
					
						WritePixel(map,px0,px1,c3)
					EndIf
				Next
				Next
				UnlockImage(image)
			EndIf
			x:+glyph.Advance()
		EndIf
	Next
	
	UnlockImage button
	Return button
End Function


thx

EDIT: Problem solved, code ^ is now working (if anybody needs)