Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to use "Bitmap Fonts"?

Discussion in 'Editor & General Support' started by vanesinha18a, May 14, 2012.

  1. vanesinha18a

    vanesinha18a

    Joined:
    Apr 11, 2012
    Posts:
    30
    How to use "Bitmap Fonts"?

    I have two files that I got to use on my game ... The first file is an extension. "Fnt" and the other file is an archive. "Png"
    In this file "png" there is some numbers and letters ...

    How do I use these font files as "my game"


    Can someone please help me with this?

    Any tutorial available?
    kisses
     
  2. Screenhog

    Screenhog

    Joined:
    Jul 2, 2009
    Posts:
    498
    As far as I'm aware, only .ttf fonts (TrueType fonts) are supported. .fnt is specifically a bitmap font, and .png is just an image file (not an archive, although it may look like one).

    Your choices are either:

    - find some way to convert .fnt into .ttf (might be possible)
    - recreate the font yourself (online utilities like FontStruct are quite good for bitmap fonts).
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use bitmap fonts for GUIText and 3DText objects; OnGUI code can only use .ttf. There's some info about using a texture as a font here, though if you don't have a matching .ttf font to supply the spacing info, then you have to set it up manually by doing Create -> Custom Font and then setting up the info properly. (In the per-character kerning array, "first" is the character and "second" is the spacing.)

    --Eric
     
  4. jasonshow

    jasonshow

    Joined:
    Jul 12, 2011
    Posts:
    2
    Eric5h5,
    can you tell me how to do this, step by step ?
    thanks a lot !
     
  5. ice99

    ice99

    Joined:
    Feb 8, 2013
    Posts:
    9
    In Unity4 i can "create custom font". I must create material, then assign texture font.png to material. Then i assign material to font. In a font properties i see "Character rects". I understand, that i input data, similar to data in myfont.txt (fnt,xml)
    ......
    char id=51 x=115 y=0 width=56 height=84 xoffset=4 yoffset=21 xadvance=65 page=0 chnl=15
    char id=52 x=0 y=170 width=59 height=82 xoffset=1 yoffset=22 xadvance=65 page=0 chnl=15
    ......
    but some data fields not corresponding with text files.

    You wrote "then setting up the info properly", but HOW i can do it. I don't mind do it manually per each letter, but in what fields i must enter what data?
     
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    For starters, try setting "index" to your char id, "Vert" x/y/w/h to your x/y/width/height, "Width" to xadvance, and "Uv" x/y/w/h to your x/y/width/height, divided by texture size (ie if your texture is 256x256, then x=128 becomes 128/256 = 0.5 for Uv: x).
     
  7. Ferb

    Ferb

    Joined:
    Jan 4, 2014
    Posts:
    21
    If x=128 and your texture size is 256, you could divide x by 256 to get 0.5, but then you have to do that for every character. I find it easier to set the tiling value for the material to 1/256 (or -1/256 for the y value), which is 0.00390625. Then in your Custom Font asset you can just use the x values as they appear in the text file.
     
  8. cjf-inc

    cjf-inc

    Joined:
    Aug 18, 2014
    Posts:
    10
  9. pcorazao

    pcorazao

    Joined:
    Mar 1, 2015
    Posts:
    5
  10. gilbertoricci

    gilbertoricci

    Joined:
    Mar 28, 2020
    Posts:
    2
  11. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    I found this online generator that let me import my fonts,style them and then export straight to unity as an .fnt. I can't find it for the life of me now.
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797