BASIC

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

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Okay, I've been having a play today, and have written a set of functions for manipulating bitmapped fonts, as follows:-

Draw Text (with or without kerning)
Centralise Text (with or without kerning)
Right Justify Text (with or without kerning)

Word Wrap Text (with or without kerning)
Word Wrap and Centralise Text (with or without kerning)
Word Wrap and Right Justify Text (with or without kerning)

Full Justification of Text (kerned only - without kerning would be too ugly!)

All of these can show text at any position on the screen, use any point to justify to, and use any width for word wrap.

As it's a bit big (since I have split everything into separate functions so you can pick and choose what you want to use) I have upped it to zshare - http://www.zshare.net/download/7127057ae41080/ - complete with a load of demo code and a font so you can see it in action.
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline D2O

  • Prof. Inline
  • *****
  • Posts: 1063
    • View Profile
    • http://www.deuteriumoxid.com
I7 2600K; 8 GB RAM ; Win10 Pro x64 | NVidia GTX 750 TI 2048MB ; Realtec OnBoard Sound;
Lenovo ThinkPad T400: XP Pro
GLB Premium-immer Aktuell

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Sounds ace Peejay - What would be really cool would be a font drawing routing using POLYVECTOR to draw the text instead.  Then you could add a colour blend parameter.

One of the strong features of Max are some commands that modify all subsequent drawing commands.  SETCOLOR is one of them, set it to WHITE and what you draw comes out at normal pixel colours.  Set at any other RGB value and it is masked, so SETCOLOR 255,0,0 will tint everything you draw red.  This applies to displaying text too.  I think GLB could benefit from this too, and could be possible to do with POLYVECTOR which takes a colour parameter for each corner.  BTW, BMax also has SetBlend, SetAlpha, SetScale, SetRotation and SetHandle which I use a lot.  Would be nice to have some of these in GLB too, which I think could be mostly possible (the exception being the differences between GLB's ALPHAMODE command and BMax's SetAlpha/SetBlend combination).

Offline Kitty Hello

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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
I knew I should have downloaded it when I saw it first, now it's gone. Any chance of uploading it again to some better host that will actually keep it online for a while?

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Never let it be said that I don't do requests! You can download it from http://www.peejays-remakes.co.uk/Bitmap Font Routines.zip - and believe me, it is well worth the download (there is a simple demo included to show what it can do)
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
Thankyou very much, this is what I will want later, was just too lazy to write it yet again after doing it once in STOS basic... :-)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
No problem. If you want to adapt it to use PolyVector (thus allowing colour effects), it is a simple edit in the DrawText() function - this is the only function that actually draws the characters to the screen
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
So it calculates the kerning live on the first load? My program took 10-20 minutes for calculating kerning... poor old 8 MHz Atari with no direct access to pixels :-)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Save it to a seperate file and load from there then.
8MHz? How much ram? 64k?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1775
    • View Profile
    • Homepage
512 kB but program was run in STOS Basic. The screen was interleaved bitmap so accessing individual pixels was not a fast task. The delay in making the kerning table is not very noticable in PeeJays code so not a problem :-)

Btw, your code is very easy to read and understand, PeeJay. And plenty of nice comments :-)

Edit: Never mind the question, stupid typo :-)

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Hehe, I don't usually code like that - comments are a luxury I only bother including when sharing code, or else it just means more typing! :D

Of course, you can always save the kerning information in a separate file (or now, store them in DATA statements) but I chose to use that method since it means it will work with any bitmapped fonts with minimal changes (just the font width and height variables)
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
Happily contributing back :-)
New version with POLYVECTOR support, hope I got it right :-)

http://gamecorner.110mb.com/games/bitmap_font_routines.zip
« Last Edit: 2008-Aug-08 by Moru »

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Ooooh, looks good to me! I think the only thing I would have done different would have been to pass colours to the PolyVector function, so that you could draw in any colours you like, rather than having them hard coded, but again, that's a simple edit for whoever wants to use the code.

I always try to bear in mind that coding is about trying to make code more and more idiot proof, while the universe is trying to make more and more idiots. So far, the universe is winning :D
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

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.