Fastest Bitmap Font character positioning

Blitz3D Forums/Blitz3D Beginners Area/Fastest Bitmap Font character positioning

Hansie(Posted 2003) [#1]
all,

what's your input here. say having a bitmap font - and use it to center X and Y the string "test" on the screen ...

whats the fatest logic/commands to achieve this?


eBusiness(Posted 2003) [#2]
(Hmmm can't understand a word, better say something meaningfull anyway)

Just figure out yourself where to put it, that's probably fastest on runtime!


FlameDuck(Posted 2003) [#3]
It depends. Is it a fixed width font, or a variable width font? Are we talking 2D 'tiles' or 3D 'quads'? BTW, whatever happened to BlitzCon DK?


Hansie(Posted 2003) [#4]
@Flameduck

a fixed font 64x64. 2D strictly

BlitzCon Denmark is still VERY high on my priority list. will post a new thread about it later today

H


Ross C(Posted 2003) [#5]
Hey, i do it by converting the integer into a string, then cycling through each digit of the string. Tehn converting the digit into a number and using it as frame number for my bitmap font image. eg 222.

Set up a loop, 1 to stringlength of integer

get loop digit

convert to integer

use integer as framenumber, and drawimage to screen. Again use the loop variable to position it.

Here's some stuff i did for it. Basic function. pass across the X,Y and the integer you want drawn.

www.rosscrooks.pwp.blueyonder.co.uk/Blitz/bitmapfont.zip


Ross C(Posted 2003) [#6]
NOTE: This is only for number, but can be easily modified :)


FlameDuck(Posted 2003) [#7]
Okay, get the width of the screen. Subtract the width of the "test" string (64*4 in this case). Divide this number by 2. This is your starting x position.

Get the height of the screen. Subtract the height of the string (64 in this case). Divide this number by 2. This is your starting y position.

Draw all four letters from the starting x and y positions. Remember to add 64 to the x position afterwsards.

If your letters on the bitmap are layed out in Fontext style (that is an ASCII table, starting with space) then all you have to do is get the ASCII value if the first letter, and subtract 32.

Then to get the x position of the letter, you need to do a modulus width test. That is the x position will be at ASCII value modulus the number of characters per row, multiplied by the width of each characters, so say you have 10 chars per line, the starting x position will be at (((asc("t")-32) Mod 10) *64).

The y position of the letter, is the same deal except you need to use integer division instead of modulus, so it'll be at (((asc("t")-32) / 10) *64).

Hope this helps. If not, send over the bitmap font and I'll write a small routine to demonstrate.


Hansie(Posted 2003) [#8]
@Ross C
Thanx a lot for your sample code

@FlameDuck
Excellent input!!

Thanx all!


Bremer(Posted 2003) [#9]
Why not load the font as an animate image with the number of frames equal to the number of letters in the font. This way you just take your ascii value of the letter minus 32 and you have the frame number for the correct character.


Hansie(Posted 2003) [#10]
@Zawran,

good idea, but so far I have never used a bitmap font which included the entire alphabet


Ross C(Posted 2003) [#11]
That's what my code example does. Unfortunetly, it only has the numbers 0 to 9 :S


FlameDuck(Posted 2003) [#12]
Why not load the font as an animate image with the number of frames equal to the number of letters in the font.
I'd wager this is (noticably) slower than manually cutting them out. At least it used to be.


Ross C(Posted 2003) [#13]
So, you'd have 26 different images, loaded into an array? I was gonna do mine that way. Can't remember why i changed my mind. It's not any harder :)


Hansie(Posted 2003) [#14]
guys, look at this function and code:

vh_fadeintro_print("abcd")


just to call the function

now the function code:

Function vh_fadeintro_print(FadeText$)
		numchars%=0
		currentchar%=0
		tempx%=0
		tempy%=0
		Upper(FadeText$)
		numchars = Len(FadeText$)
		tempy = (vh_scrheight/2-vh_fadeintro_fntheight)
		tempx = ((vh_scrwidth-numchars*vh_fadeintro_fntwidth)/2)
		While numchars <> 0
		DrawImage (vh_fadeintro_fnt,tempx,tempy,currentchar)
		tempx = (tempx+vh_fadeintro_fntwidth)
		numchars = numchars - 1
		Wend
End Function


Problem? well, I loade my font using LoadAnim, and the font begins with "A" then "B" etc. my problem consists of using the "currentchar" in the DRAWIMAGE command ... How do I get "A"=0 for currentchar, "B"=1 etc?

PS - its a 64 x 64 fixed sized font


MutteringGoblin(Posted 2003) [#15]
Hi, Hansie it's the middle of the night here and I only very quickly looked at your post so forgive me if this is wrong...

You want to cycle through a string and extract characters one at a time... as integers in the range 0 - 25? Okay, you should be able to adapt this code to work in your function.


Local MyString$,Length,Char

MyString$ = "ABCD"
Length = Len(MyString$)

For i = 1 To Length
    Char = Asc(Mid(MyString$,i,1)) - 65
    Print Char
Next

WaitKey

End


Also, I think you are using the 'Upper' function wrongly. You need to reassign the new string to the old one, like this:

a$ = Upper(a$)



FlameDuck(Posted 2003) [#16]
So, you'd have 26 different images, loaded into an array?
No. I'd have a single image loaded with LoadImage and use DrawImageRect or whatever it's called.


Hansie(Posted 2003) [#17]
@MutteringGoblin

Thanx, mate


Ross C(Posted 2003) [#18]
Oh, that's an idea to. Thanks :) (sorry for mini hi-jack ^_^)