Author Topic: Bitmapped Font Functions - Everything but the kitchen sink!  (Read 18497 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
LOL! Indeed. Dad of a friend is a teacher for computer classes. He once said, that the easier the computers are to use, the more people act dumb. In 80s you could teach BASIC or PASCAL at school. Today you can be happy to teach Wordpad.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
I wasn't sure how to do the colours so they would be setable in an easy fashion. Now after a good nights sleep I figured I'll just make a global array holding all the corners values and two functions to easier set the colors. Also added a function for storing a color and restoring it again. Can be rewritten to store many colors and just access them with a word or a number if one feels like it :-)

Forgot to mention that for full color-freedom you need a font that is white, otherwise you can't set some colors because they will just filter away the colors not needed and leaving you with black :-)
For example a red font will not be possible to make blue, if I got it right.
http://gamecorner.110mb.com/games/bitmap_font_routines.zip

...wordpad, what is that? :-)
« Last Edit: 2008-Aug-09 by Moru »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
Is it possible to see the ASCII code of characters above ascii 127? If I use asc() I get negative numbers when I try to convert Ã…ÄÖ. And yes I know that ascii only covers the first 127 characters but what am I supposed to use for the rest of the swedish and other foreign characters?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
They are mapped to signed char.
so,
Code: GLBasic [Select]
a = ASC(i)
if a<0 then a=256-a
should give you what you need.
Is that stupid? I'll better change that, so it returns positive numbers in the first place, OK?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
Sounds good to me, signed char isn't very useful in this case :-)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Update online.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
Great job Gernot thanks! Now we can use swedish characters too, and the standard fonts from the fontcreator whithout need of creating a specially formated font file.

I also fixed a bug with the unkerned printing, When you put an "i" and a "w" next to eachothers they looked welded together.

No more excuses for not printing with proportional fonts! I also tried it on our GP2X and it ran just fine, no visible slowdowns to calculate the kerntables even though it has to do double the work now.

The source file contains full examples with comments, it's very easy to learn how to use this code.

Proportional bitmap fonts in GL-Basic
« Last Edit: 2008-Aug-09 by Moru »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Aces! Thanks.

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
If only my games were played with as long ..... :D

Great job
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
Added shadow support (Thanks Hemlos for the idea :-)
this code is so easy to work that it took me 45 minutes to add support for shadows including the time it took to rewrite all the examples to use shadows. Thanks again, PeeJay for doing the hard work and making it free for us to use!

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
The font is changeable with the built-in font editor of GL-Basic, that's why it takes a bit to load but on my computer and my GP2X it's more like 2 seconds, why is it taking 20 seconds for you?

Transparent mode should be adjusted with just putting in ALPHAMODE before you draw the font. You can also put in alphachannel with photoshop in the font if you want.

Do you have a baby? Do you even know what work-load is? :-)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile

Do you have a baby? Do you even know what work-load is? :-)

Do i ever...try teenagers.

Cool love the Schnipsel
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
The program "stalls" at startup while it precalculates the kerning for the font - this could be exported to an external file to eliminate this, but it is currently done that way to work with ANY bitmapped font. If it's taking more than a couple of seconds, though, there's something not right somewhere!

Of course the font can be changed - simply load in an alternative font, and change the fontwidth and fontheight values.

At some point when I get bored I will revisit this set of routines and expand on them, as it seems a lot of people are finding them pretty useful (there's an understatement!) and now GL supports default parameters for function calls, it means I can make tweaks I couldn't do before (well, not if I wanted to keep the code really tidy!)

www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
I have been working on a precalculating routine but it seems the most time is taken from grabbing the sprites from the bitmap. Precalculation didn't do much for speed increase. On the other thand I'm running two 3D games in the background while testing this code and I'm still not getting any lower speed than 2-5 seconds

Marquee is almost done, just a logical bug that I need some peace to think thru.

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
You should see a massive speed increase (to basically instantaneous!) using an external file for precalculation.

The kerning is simply calculating the width of each character, so by writing a separate routine, you can calculate these values, then save them out into a separate file. Then, in the main program, load this file in and put the values into the array - no need to calculate again.

This is one of the amends I have been planning, as well as adding the ability to use multiple character sets of multiple sizes
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity