17
\$\begingroup\$

I'm about to pick up computer graphics once again for an university project. For a previous project I used a library called FTGL that didn't leave me quite satisfied as it felt kind of heavy (I tried lots of rendering techniques, text rendering didn't scale very well).

My question is, is there a good and efficient library for this? If not, what would be the way to implement fast but nice looking text? Some intended uses are:

  • Floating object/character labels
  • Dialogues
  • Menus
  • HUD

EDIT: Preferably it could also load fonts

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is a "which technology to use question", and thus should probably be closed. \$\endgroup\$ Commented Jun 11, 2013 at 16:26

5 Answers 5

4
\$\begingroup\$

A popular framework is Crazy Eddie's GUI.

But whilst that is appealing, its not unusual to roll your own (and perhaps regret it as the scope increases later ;))

Its normal to have your glyphs on bitmaps and then draw the bitmaps using OpenGL.

Sometimes you show transient text that might only appear for a handful of frames. Just using GL_QUADS+glVertex will be sufficient. But for any large quantity of text or any long duration of visibility its well worth putting the GL_QUADS in a VBO - I've noticed big performance improvements from this.

There is of course the question of generating the actual glyphs that you need. There are programs like bmfont that you can use for that. Or you might need rather more complicated rendering, e.g. freetype on demand. I've been using bmfont with my own renderer quite happily, its very straightforward to deduce.

\$\endgroup\$
0
9
\$\begingroup\$

There are a lot of ways - depending on what you want... Like everywhere else, there isn't something like "the best solution". Which plattform is your target? Which language are you using? What is about text resizing/rotation - is it necessary? Do you need to be able to render TrueTypeFonts? Whats about Multilanguage/Unicode? How do you want to store your text (which encoding etc.)?

I used in the past also FTGL, as well as pure freetype (http://www.freetype.org/ FTGL is based on this), different kind of bitmap fonts, outline fonts... Now I'm mostly addicted to bitmap fonts, but thats only my personal preference. Because I dont want to deal with different charsets, encoding and stuff like that anymore - and licensing for bitmapfonts is also easilier and cheaper than for TrueTypeFonts. And its usable on every plattform that can load images. I use simply an quad in openGL and map a part of my texture on it. The other side is: The font will be only clean resizable at a factor about +/-50%. If you can live with that, I would suggest using a bitmapfont.

If you have also to deal with different encoding/charsets you should find a way to load and use TrueTypeFonts (like with freetype, using another library or with your own implemenation)...

Also have an look at nehes different tutorials on this topic:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13 Bitmap Fonts

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=14 Outline Fonts

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=15 Texture Mapped Outline Fonts

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=17 2D Texture Font

Good luck!

\$\endgroup\$
2
  • \$\begingroup\$ +1 Thanks for the valuable info on performance, I did know about NeHe's tutorials. I think I did use bitmap fonts... but it didn't scale: about 60 labels floating in a scene above spheres joined by lines, any insight to that? (I was thinking I should have looked for a way to implement a flyweight pattern) \$\endgroup\$ Commented Jan 22, 2011 at 10:38
  • 1
    \$\begingroup\$ Caution: NeHe's tutorials are for the old fixed function pipeline and don't get updated often. If you are looking for a modern OpenGL solution see stackoverflow.com/questions/5262951/… \$\endgroup\$
    – brita_
    Commented Jul 18, 2016 at 18:40
6
\$\begingroup\$

If you want to use bitmap fonts, you can't go far wrong with the Angelcode Bitmap Font Generator: http://www.angelcode.com/products/bmfont/

It converts a truetype font to one or more textures (with nicely packed glyphs), and outputs a little file containing the UVs and spacings (I find that the XML output is particularly easy to work with, and the quality of the spacing data is generally very good, even without true kerning)

\$\endgroup\$
1
\$\begingroup\$

I'm using the libraries of Sean Barret to render truetype-glyphs under OpenGL (stb_image, stb_truetype).

The Recast/Detour-project is using these libraries to create an user interface (IMUI)

\$\endgroup\$
0
0
\$\begingroup\$

Consider QML. It's a fully functional UI library with an easy to use syntax. Its feature set is significantly better than CEGUI in my experience, and it has better documentation, support and community since its primary target is desktop applications and the ability to render offscreen is just sort of a bonus.

Pros:

  • It uses OpenGL on the back end for all rendering
  • It can load any font available to the host system and can also parse additional fonts you include as resources
  • It uses signed distance field text rendering for efficient and high quality output
  • It can render directly to an OpenGL texture, so you can place the results in your game environment easily
  • Qt has lots of language bindings

Cons:

  • Qt is a big framework
  • Using QML in Direct3D or Vulkan projects requires jumping through hoops to get the GL texture into the appropriate API (or waiting for someone to write native D3D / Vulkan renderers for QML)
  • There are still some minor quirks in QML where it will try to use a native control even if you're rendering to an offscreen surface, like when you try to open up a dropdown for a list item.
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .