Fonts compatible with devkitarm (or how to make them!) (libnds)

Discussion in 'NDS - Emulation and Homebrew' started by kerneldev, Jan 13, 2012.

  1. kerneldev
    OP

    kerneldev Member

    Newcomer
    26
    4
    Jan 11, 2012
    United States
    The Mud Ball
    Hi,

    I've been compiling resources for homebrew fonts suitable for the DS:
    • http://www.proggyfonts.com/index.php?menu=download
    • http://www.angelcode.com/products/bmfont/
    But thus far I've been unable to grok how the fonts, especially TTF ones, can be converted to a BMP bitmap font suitable to be used with libnds. I'm writing a tool I plan on releasing when it has produced fruits (it has to do with investigating the DS mode in 3DS) and would love to be able to use crisp fonts rather than the default console one (which looks mildly wrong with DeSmuME).

    Can anybody help with understanding how to create fonts for libnds? Perhaps a HOWTO?
     
  2. DanTheManMS

    DanTheManMS aka Ricochet Otter

    Member
    4,330
    106
    Jun 2, 2007
    United States
    Georgia
    You could look into whatever DSReader used for rendering TTF fonts on the DS on the fly.
     
  3. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,529
    21,457
    Sep 13, 2009
    Poland
    Gaming Grotto
    It's my understanding that the DS may use two types of fonts - based on a tiled background, where each tile represents one letter, and those are made quite easily, since all you have to do is put each letter in its corresponding "slot" and fonts that are actively drawn on-screen on a bitmap-like layer, difference being that tiled fonts cannot be resized and take less space while drawn fonts work exactly the same as their equivalents on the PC.

    I have no idea how to create the latter, but for the former you may dig up a program called dsFont which will do most of the work for you, leaving you with a pre-rendered image with each letter in a separate tile for you to "re-touch" where needed. If you won't be able to find it, PM me for a copy - it's freeware.
     
  4. iSubaru

    iSubaru Kitsune

    Member
    360
    18
    Apr 14, 2009
    Poland
    Gensokyo
    Foxi4 You are 100% correct, that's how it goes
    Basically (but not exactly) it's like this
    - Free Line
    - Special characters and numbers
    - Capital Letters
    - Small Letters
    It's not exact because explaining it from table would take a bit of time...but idea is the same, it's BMP image with letters, symbols and numbers in their proper "slots" (XY positions)
    Dunno, maybe Devkitpro has example image somewhere? Like in "text" examples?
     
  5. Schmendrick

    Schmendrick Advanced Member

    Newcomer
    55
    3
    Sep 12, 2009
    Netherlands
    Another option is to use the 3D engine to display text. I made a little program that takes a font pcx file, and adds a header in front of it containing letter sizes. Then I just use the 3D engine to draw quads with the proper uv coordinates. Works like a charm! And without too much extra work allows you to scale and rotate everything.
     
  6. LeRodeur

    LeRodeur GBAtemp Regular

    Member
    162
    10
    Dec 12, 2009
    France
    Would be easier to do as said before, make a bmp with your file, convert it into a tileset in the good order with the ascii table so that when you have to draw a string you only have to do something like this
    For(i=0;*sting != /0;i++)
    Bgmap[x+(x+i)%32][y+(x+i)/32]=*string;
    string++;

    You could also check for /n etc
    the latter tool should place the characters in the right order
    the only problem is that you can't make your characters of various sizes
     
  7. Schmendrick

    Schmendrick Advanced Member

    Newcomer
    55
    3
    Sep 12, 2009
    Netherlands
    Yes, using a tiled bg may be easier, but much less flexible. My text system uses identical font images (or tilesets), it just uses the 3D engine to render them to the screen, and it allows for non-fixed width text, custom colors, etc. Anyway, I just figured I'd give another alternative to writing text to the screen :)
     
  8. LeRodeur

    LeRodeur GBAtemp Regular

    Member
    162
    10
    Dec 12, 2009
    France
    Actually, if he meant a font compatible with the iprintf function from libnds, it will be a bit more difficult to generate, as libnds seems not use the ascii, but a slightly different one (used in all nintendo ds games? with strange smileys etc)
    to see the table just use this litle code:
    Code:
    int i;
    char test[256];
    for (i=1;i
     
  9. CoolAs

    CoolAs Advanced Member

    Newcomer
    75
    17
    Oct 21, 2011
    Hrm, well I know that Dirbaio made a .ttf to .bin (Dirbaio's own format) converter.
    Then he wrote some code to print user specified characters and strings (using the font from the .bin file) onto a bitmap background. It was commited to the home-smash svn repo ages a go... then was deleted.
    But if you checkout the current revision then run "svn update -r x" (replacing x fom 0 to 24) untill you find the font printing code... You will still have to ask him for the converter though - that was not commited at all, and I don't have a copy of it.