10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: Custom Font Parser/Display  (Read 6122 times)

vdecampo

  • Forum Howler
  • ****
  • Posts: 140
  • Apocalypse is Forever!
    • View Profile
    • Easton Computers
Custom Font Parser/Display
« on: March 06, 2008, 06:27:41 AM »
While developing Hex Factor, I created a library to parse and display font files created with a program called ppFonter...(found here..http://www.pixelperceptions.com)

The library reads in the XML and BMP files exported from ppFonter and lets you use the font in your FB app. It currently only supports 256x256 font files(single page), but that was large enough for my purposes.

You can download an example here...
www.ftpisland.com/files/cFont.zip Win32 109kb

The lib is very easy to use with only a few lines of code...
Code: [Select]
'***************************************************
'* cFont Library - (c) 2007-2008 Otium Productions *
'*                                                 *
'*              by Vincent DeCampo                 *
'***************************************************

#Include "fbgfx.bi"
#Include "ppfonter.bi"

ScreenRes 800,600,32

Dim MyFont1 As _cFont = "fontmap"
Dim MyFont2 As _cFont = "joker"

   MyFont1.DrawText (0,400,100,"This text is CENTERED",,0,AlignCenter)
   MyFont1.DrawText (0,400,130,"This text is to the LEFT",&hFFFF00,0,AlignLeft)   
   MyFont1.DrawText (0,400,160,"This text is to the RIGHT",&hFF00,0,AlignRight)
   
   MyFont2.DrawText (0,400,300,"This text is CENTERED",,0,AlignCenter)
   MyFont2.DrawText (0,400,330,"This text is to the LEFT",&hFFFF00,0,AlignLeft)   
   MyFont2.DrawText (0,400,360,"This text is to the RIGHT",&hFF00,0,AlignRight)

Sleep
Hope someone finds this useful. Please let me know if anyone has a request for some feature I did not incorporate.

Cheers!
-Vince[/url]
Cheers!
-Vince

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Re: Custom Font Parser/Display
« Reply #1 on: March 06, 2008, 05:46:30 PM »
Cool! I'm not sure I'll end up using it thought, because I have a solid choice in this area.

Still, I like the fonts you included and the color feature.

Thanks for providing this to community. :)
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

relsoft

  • Recruit
  • **
  • Posts: 48
    • View Profile
    • Email
Re: Custom Font Parser/Display
« Reply #2 on: March 06, 2008, 10:20:10 PM »
Nice! Do you have OpenGL support?

nkk_kan

  • Forum Howler
  • ****
  • Posts: 193
  • Let's rocK~!
    • Yahoo Instant Messenger - nkk_kan
    • View Profile
    • nkk's code cache
    • Email
Re: Custom Font Parser/Display
« Reply #3 on: March 06, 2008, 10:28:22 PM »
Excellent! Only a bit of documentation wouldn't hurt :P

i got a problem though...



here's my (yours but modified a bit) code

Code: [Select]
'***************************************************
'* cFont Library - (c) 2007-2008 Otium Productions *
'*                                                 *
'*             Programming & Design by             *
'*              by Vincent DeCampo                 *
'***************************************************

#Include "fbgfx.bi"
#Include "ppfonter.bi"
using fb
ScreenRes 800,600,32
dim as fb.image ptr joke
Dim MyFont1 As _cFont = "fontmap"
Dim MyFont2 As _cFont = "joker"
bload "scorpio.bmp",0
joke = imagecreate(400,488)
get(0,0)-(399,487),joke
cls
put(0,0),joke,trans


   MyFont1.DrawText (0,400,100,"This text is CENTERED",rgb(200,0,0),0,AlignCenter)
   MyFont1.DrawText (0,400,130,"This text is to the LEFT",rgb(200,0,0),0,AlignLeft)   
   MyFont1.DrawText (0,400,160,"This text is to the RIGHT",rgb(200,0,0),0,AlignRight)
   
   MyFont2.DrawText (0,400,300,"This text is CENTERED",rgb(200,0,0),0,AlignCenter)
   MyFont2.DrawText (0,400,330,"This text is to the LEFT",rgb(200,0,0),0,AlignLeft)   
   MyFont2.DrawText (0,400,360,"This text is to the RIGHT",rgb(200,0,0),0,AlignRight)

  Sleep
 

now shouldn't the text come over the image?
and i think i can see some text in the red tail of scorpio..

nkk

vdecampo

  • Forum Howler
  • ****
  • Posts: 140
  • Apocalypse is Forever!
    • View Profile
    • Easton Computers
Re: Custom Font Parser/Display
« Reply #4 on: March 07, 2008, 07:22:23 AM »
@nkk_kan

I designed the font display to blend the text to whatever is already on the target surface. The drawback to this is exactly what you've tried here, it won't display on white. If I add different options for blending (ie: OR, XOR, AND, TRANS, ALPHA) then you would be able to display on different colors better. Space is black, which is what this was originally designed for.   ::)

If you are interested in using it, I will try to make these additions soon.

@relsoft

I have no idea what would be needed for it to support OpenGL. If OpenGL supports FB images, you can always print to an image instead of the screen.


-Vince
« Last Edit: March 07, 2008, 07:24:59 AM by vdecampo »
Cheers!
-Vince

nkk_kan

  • Forum Howler
  • ****
  • Posts: 193
  • Let's rocK~!
    • Yahoo Instant Messenger - nkk_kan
    • View Profile
    • nkk's code cache
    • Email
Re: Custom Font Parser/Display
« Reply #5 on: March 07, 2008, 09:09:31 AM »
ok i understood why it does that!

Did you "Type" those xml files up??!
because if i have to enter those values manually...i don't think i can use this  ??? :-\
ofcourse we could make a program which could do that...

notthecheatr

  • Global Moderator
  • Forum Sage
  • *****
  • Posts: 351
  • Who's the guy from 21 Jump Street?
    • AOL Instant Messenger - notthecheatr
    • Yahoo Instant Messenger - TheMysteriousStrangerFromMars
    • View Profile
    • notthecheatr Home
    • Email
Re: Custom Font Parser/Display
« Reply #6 on: March 07, 2008, 10:01:12 AM »
ok i understood why it does that!

Did you "Type" those xml files up??!
because if i have to enter those values manually...i don't think i can use this  ??? :-\
ofcourse we could make a program which could do that...

Looks like he made it with the ppFont tool at http://www.pixelperceptions.com/ - too bad that tool isn't freeware :-\
The funniest thing happened yesterday.

vdecampo

  • Forum Howler
  • ****
  • Posts: 140
  • Apocalypse is Forever!
    • View Profile
    • Easton Computers
Re: Custom Font Parser/Display
« Reply #7 on: March 07, 2008, 10:28:45 AM »
ok i understood why it does that!

Did you "Type" those xml files up??!
because if i have to enter those values manually...i don't think i can use this  ??? :-\
ofcourse we could make a program which could do that...

Looks like he made it with the ppFont tool at http://www.pixelperceptions.com/ - too bad that tool isn't freeware :-\

No it's not free but trial-ware. But like all programs, if I like it and will use it (and the price is fair), i pay for it. It was a reasonable $20 to add that capability for me.

-Vince
Cheers!
-Vince