Search Unity

Text Outline

Discussion in 'Immediate Mode GUI (IMGUI)' started by demonpants, Oct 6, 2008.

  1. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    Hey there.

    Does anyone know of a way to create an outline around my text, a la Photoshop layer effect? Just increasing the size of a different label and drawing it underneath wouldn't work unless I did it for each letter individually and laid them out one by one, pixel by pixel, but that's pretty ridiculous.

    Any method of using shaders, shadows, etc. that might work?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you use GUIText objects, you can make a custom bitmap font that includes an outline. Otherwise, if this has to be in OnGUI, you can draw the text 5 times: shift left 1 pixel, right 1 pixel, up 1 pixel, down 1 pixel (all of these with the outline color), then finally in the normal position with the normal color. I think someone posted a routine somewhere that automated this.

    --Eric
     
  3. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    I'm using GUIText objects, actually – I was hoping to avoid the pixel approach, so it's nice that it appears I can.

    How do I go about making the custom bitmap font? I already messed around with this but had poor results and figured it wasn't possible. Basically I looked for a while for a font tool that allowed me to turn a TTF into a bitmap, then I wanted to open it in Photoshop to apply the outline effect. Unfortunately, Photoshop can't read a BDF, or anything else that the font tool I got could export.

    But in the end it seems I need to do this:
    1) Export a TTF into a BDF.
    2) Export the BDF into a format Photoshop can read like PNG.
    3) Apply the outline to the PNG in Photoshop, save it.
    4) Import the PNG to a BDF.
    5) Put the BDF into Unity.

    Potentially steps 1 and 2 can be combined if I find the right program.

    In any case, can anyone point me to programs that can perform any or all of those steps, and/or tell me a better way to do this?
     
  4. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    You don't actually use the BDF format. A bitmap font in Unity is just a normal texture (PSD, Targa, PNG, etc). Unity expects to find the letters in a grid. You have to specify kerning per-character.

    The texture will look something like:



    And the font setup like:

     
  5. demonpants

    demonpants

    Joined:
    Oct 3, 2008
    Posts:
    82
    Ah.

    Wow.

    That's a gigantic pain. It must take 2 hours to get all the values right for each letter. Here's to hoping they improve this functionality in the future.
     
  6. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    In practice it isn't super painful. Could be a lot better. In Unity 2.1 you can no longer see the characters (you have to type in their ASCII character codes).

    The secret is alt-clicking to expand all kerning values in the array and then right-click-dragging to adjust. Keep a GUIText with the whole alphabet in the scene.
     
  7. BF77

    BF77

    Joined:
    Jun 30, 2008
    Posts:
    1
    Sorry, i'm pretty new at this... After creating a custom font, how do i assign the font texture i created to it? Any help is appreciated.
     
  8. PizzaGuy213

    PizzaGuy213

    Joined:
    Nov 23, 2010
    Posts:
    305
    Why can't all this be done anymore?
     
  9. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    781
    It can still be done. Project pane -> Create -> Custom Font.