Problems generating fonts with -extra glyphs

Hi,

I’m trying to embedd extra glyphs in a text I generate using egg-mkfont.
Specifically, I want character 17 (=0x11) to use a special graphic. The graphic is 16x16 pixels in size

However, so far my attempts have not worked.
Here’s what I do (plus commandline output):

First, I generate my extra glyph as a texture card

...\data\fonts>egg-texture-cards -o extra.egg 17.png

Writing extra.egg

Then, I attempt to embed it in the font: (for demonstration purposes, I only generate two other chars)

...\data\fonts>egg-mkfont -o test.egg -chars 0x020-0x022 -extra extra.egg framd.ttf

Reading 17.png
Deleting test_1.rgb
Resizing test_1.rgb to 16 16
Resizing test_1.rgb to 16 32
Generating new test_1.rgb
Reading 17.png
Writing test_1.rgb
Deleting test_1.rgb
Generating new test_1.rgb
Writing test_1.rgb
Writing test.egg

However, the generated font file doesn’t reference my new character 17 properly. The egg file reports it to be in the generated texture palette, but it doesn’t show up.
Here’s the full .egg:

<Texture> test034 {
  test_1.rgb
  <Scalar> format { alpha }
  <Scalar> wrap { clamp }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear_mipmap_linear }
  <Scalar> anisotropic-degree { 0 }
  <Transform> {
    <Matrix3> {
      0.680921 0 0
      0 0.375 0
      0.315789 0.65625 1
    }
  }
}
<Texture> test033 {
  test_1.rgb
  <Scalar> format { alpha }
  <Scalar> wrap { clamp }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear_mipmap_linear }
  <Scalar> anisotropic-degree { 0 }
  <Transform> {
    <Matrix3> {
      0.490385 0 0
      0 0.75 0
      -0.0576923 0.28125 1
    }
  }
}
<Texture> 17 {
  test_1.rgb
  <Scalar> wrap { clamp }
  <Scalar> minfilter { linear }
  <Scalar> magfilter { linear }
  <Scalar> anisotropic-degree { 0 }
  <Transform> {
    <Matrix3> {
      0.625 0 0
      0 0.625 0
      0 0.375 1
    }
  }
}
<Group> {
  <Switch> { 1 }
  <Scalar> fps { 2 }
  <VertexPool> vpool {
    <Vertex> 0 {
      0 1.13333 0
    }
    <Vertex> 1 {
      0.25 0 0
    }
    <Vertex> 2 {
      0.0166667 -0.0333333 0
      <UV> { 0.117647 0.0416667 }
    }
    <Vertex> 3 {
      0.233333 -0.0333333 0
      <UV> { 0.882353 0.0416667 }
    }
    <Vertex> 4 {
      0.233333 0.7 0
      <UV> { 0.882353 0.958333 }
    }
    <Vertex> 5 {
      0.0166667 0.7 0
      <UV> { 0.117647 0.958333 }
    }
    <Vertex> 6 {
      0.266667 0 0
    }
    <Vertex> 7 {
      0.0333333 0.366667 0
      <UV> { 0.0869565 0.0833333 }
    }
    <Vertex> 8 {
      0.35 0.366667 0
      <UV> { 0.913043 0.0833333 }
    }
    <Vertex> 9 {
      0.35 0.7 0
      <UV> { 0.913043 0.916667 }
    }
    <Vertex> 10 {
      0.0333333 0.7 0
      <UV> { 0.0869565 0.916667 }
    }
    <Vertex> 11 {
      0.383333 0 0
    }
  }
  <Group> ds {
    <PointLight> {
      <VertexRef> { 0 <Ref> { vpool } }
    }
  }
  <Group> 32 {
    <PointLight> {
      <VertexRef> { 1 <Ref> { vpool } }
    }
  }
  <Group> 33 {
    <Polygon> {
      <TRef> { test033 }
      <VertexRef> { 2 3 4 5 <Ref> { vpool } }
    }
    <PointLight> {
      <VertexRef> { 6 <Ref> { vpool } }
    }
  }
  <Group> 34 {
    <Polygon> {
      <TRef> { test034 }
      <VertexRef> { 7 8 9 10 <Ref> { vpool } }
    }
    <PointLight> {
      <VertexRef> { 11 <Ref> { vpool } }
    }
  }
  <Comment> {
    "egg-texture-cards -o extra.egg 17.png"
  }
  <Group> {
    <VertexPool> vpool.vpool1 {
      <Vertex> 0 {
        -0.5 0.5 0
        <UV> { 0 1 }
      }
      <Vertex> 1 {
        -0.5 -0.5 0
        <UV> { 0 0 }
      }
      <Vertex> 2 {
        0.5 -0.5 0
        <UV> { 1 0 }
      }
      <Vertex> 3 {
        0.5 0.5 0
        <UV> { 1 1 }
      }
    }
    <Group> 17 {
      <Polygon> {
        <RGBA> { 1 1 1 1 }
        <TRef> { 17 }
        <VertexRef> { 0 1 2 3 <Ref> { vpool.vpool1 } }
      }
    }
  }
}

Any ideas what I’m doing wrong? Does the .egg look correct?
For what it’s worth, I also tried telling egg-mkfont to explicitly include char 17:

...\data\fonts>egg-mkfont -o test.egg -chars 0x011,0x020-0x022 -extra extra.egg framd.ttf

But that wasn’t sucessfull either…

Thanks in advance,

Johannes

When you use the -extra command line option, you need to provide an egg file that is formatted exactly the same way that egg-mkfont formats the glyphs it generates. The egg file as output from egg-texture-cards isn’t quite right. In particular, you need to have a and a entry within the group (the point light represents the width of the character–the next character will be placed on the point light).

Note that you don’t need to generate a new font if your goal is to embed a graphical object within text. Panda’s text system allows you to do this already, with any number of separate graphical objects of your choosing, though it isn’t mentioned in the manual.

Read the page in the manual about changing the text properties on-the-fly via the TextPropertiesManager. Then look at the generated API for TextPropertiesManager.setGraphic(). The idea is, you can associate any number of graphic images (i.e. NodePaths) with names in the global TextPropertiesManager object, and then when you put the string “\5myname\5” in your text, it will insert the graphic associated with “myname”.

If you want to allow Panda to compute the bounds of your graphic automatically, just pass a NodePath to tpMgr.setGraphic(). If you want to have explicit control over the scale of your graphic and its placement within the text line, wrap it in a TextGraphic object first.

David

Thank you, that sounds like a perfect solution for me. I’m going to take a closer look at the TextPropertiesManager.