6

I'm quite a noob with libGDX for Android (nice OpenGL wrapper that can also work on PC), and I've read some nice examples of how to show images and shapes. However, when I wanted to check out how to show text, I noticed that the only thing I could see that this library supports is BitmapFont, which uses a bitmap for each character. It's ok for some resolutions and font sizes, but it becomes blurry/pixelated for other cases.

Is there any other way to show text using this cool library? Some kind of way to show vector fonts, and also use more popular fonts files extensions other than ".fnt"?

GraphicsMuncher
  • 4,583
  • 4
  • 35
  • 50
android developer
  • 114,585
  • 152
  • 739
  • 1,270

2 Answers2

4

There is a recent entry on the badlogic blog about generating bitmap fonts on the fly from TrueType font files that should address your problems with packaged font files that are ugly when scaled.

When I was new to Android and libGDX I spent some time looking for a vector font solution to draw scalable text via libGDX. I never found anything (not even generic Java or generic Android). Most font solutions I found are built on bitmaps or were very complex rendering systems (that would be hard to adapt to OpenGL). This seems a bit odd to me too, and I haven't found a coherent explanation.

P.T.
  • 24,557
  • 7
  • 64
  • 95
  • this looks very promising , and people there wrote that it worked for them . how come it's not built in yet? does it have some bugs that need to be fixed ...? – android developer Mar 11 '12 at 08:58
  • also, isn't there another solution that includes drawing low level lines and pixels for the fonts , instead of having to create bitmaps ? – android developer Mar 11 '12 at 09:07
  • As to why its not built in, I suspect its not part of libgdx because its new and hasn't gotten a lot of testing. I'm sure they'd be interested in help or reports on its usefulness. As to other solutions that use OpenGL primitives, I've looked and haven't found anything (of course I can't prove a negative, though). I suspect most folks like the optimization of generating a bitmap, though. – P.T. Mar 11 '12 at 20:01
  • ok then . you've earned my "V" for your answer . hope that i will see a better library for libgdx that does show vectorized fonts in a good manner .thank you for your help! – android developer Mar 11 '12 at 23:47
  • i've found an interesting post describing a solution of showing some characters using the android framework . i wonder how well those can work: http://code.google.com/p/libgdx/issues/detail?id=609 – android developer Mar 23 '12 at 16:23
  • i've also found a libgdx library that also handles this issue. however , i can't get to download and use it. its name is "gdx-stb-truetype" . – android developer Mar 23 '12 at 22:52
  • another alternative is to create large bitmap fonts , using this nice tool: http://code.google.com/p/libgdx/downloads/detail?name=hiero.jar&can=2&q= – android developer Mar 24 '12 at 10:01
0

I don't think there is a proper ways to do so, because libgdx works on openGL too. OpenGL uses textures for displaying images, so that your device is able to draw images hardware accelerated. I don't use libgdx but probably you can write your own function to draw first your vector-based fonts on a texture and then draw your texture on screen. -> But then it's not vectorized anymore.

TheWhiteLlama
  • 1,276
  • 1
  • 18
  • 31
  • well , if i call to a function that knows in which size to show the font , wouldn't it be the exact same as showing it in the "correct" way ? surely there is some library out there that does it , no? – android developer Mar 10 '12 at 19:21