# OpenGL font rendering

## Recommended Posts

Hello,

I have a few questions regarding OpenGL font rendering. But to generalize it:

1. What's the current state of art regarding font rendering in OpenGL?

I have many sub-questions as well as many own ideas and requirements, but I would like to hear how you do it and what the advantages/disadvantages are.

2. Are you using textured quads, tesselated outlines, maybe distance fields or something entirely different?

3. Can you scale your text freely or are you limited to a (few) fixed size fonts?

4. How cross platform is it?

5. Does your way of rendering fonts support vertex buffers or are you using the fixed function pipeline?

6. What about internationalization, do you support any language as long as the font contains the required characters or do you only support a fixed set of languages?

7. How hard was it to implement/build your solution?

For my own project I guess I would use tesselated outline fonts. Because of their scalability, the potential to use the vertex shader to transform them and because you can use the same anti-aliasing as you do for your other geometry.

I already started by building a small tool that creates a mesh for each glyph in a font. The tool will be used offline in the build step and the meshes shipped with the game, since I believe just loading a few thousand meshes is faster than tesselating them on the users computer. It's also much more deterministic, since I won't have to rely on the glu tessellator installed on the users computer and can test for exact output.

Now I do plan on using SIL Graphite to generate the positions for each glyph, that way I do have the same support for languages on all platforms that graphite supports. Even minority scripts in case I would really like to translate my project into some language that the operating system is not supporting.

That's my plan so far. Maybe when I have time I will actually put it in action.

##### Share on other sites

1. No idea

2. Textured quads. It's fast and simple, yet surprisingly effective. Mipmapping can handle font scaling better than you'd think--better than actual geometry without antialiasing--and it's very very fast.

3. Any font.

4. The fonts are loaded and rendered using SDL_ttf, so it is completely cross-platform.

5. Actually, my font module really only serves to create the texture. What is done with it is up to you.

6. Anything SDL_ttf can do.

7. Easy. Ridiculously easy.

I personally recommend against anything too complicated (e.g. tessellated or mesh-based fonts. Maybe there's some special applications (e.g. flying through a piece of text for an effect) but really, rasterized fonts are fast, easy, robust, portable, and easy-to-implement.

##### Share on other sites

I've had good results using glfont. It is fairly simple to integrate into a project and is fast. I've used it on Windows and Linux, but see no reason why it won't work on OS X. The only causion is that the routine for reading the font file requires a slight modification on 64-bit machines (the use of sizeof causes a problem becuase the format of the file is based on 32-bit data types).

##### Share on other sites
Textured quads with distance fields. This works very well for both scaling up and down, and you can nicely antialias at any scale (plus, special effects if you want). Shaders are well-documented in several papers and readily available with liberal licenses, so implementing it is not all that hard. Performance is almost identical to using normal textured quads on modern GPUs.

Tesselated outlines are forbidding if you need to render more than a few dozen characters in real time. Edited by samoth

##### Share on other sites

1. there's a state-of-the-art font rendering ?

3. any - but my personal preference is to keep things crisp and scale so that texels are exactly stretched or smashed into a concise number of screen pixels

4. as much as OpenGL itself is

5. I use display lists to render character strings, where I can basically just glCallList(string) after applying appropriate matrix transforms to put it where I want

6. I built my font system around a simple texture packing/quantization setup that I devised so I could store font textures inside my executables by including a header. I wrote a tool which will take any sized font texture and spit out a header file to include in my projects that contains a packed array of texels and various font character / texture dimensions needed by the font rendering system itself.

7. It was easy, but it was a slow evolution that occurred during work on different projects over the course of a few years.

On a side note, as far as game development is concerned, I am particularly attentive to how much CPU/GPU text output consumes. I feel that it is even overkill to use quads (two triangles) per character, because I'd rather be using those triangles on the game scene itself. Ideally some sort of precomputation setup that generates a single texture or vertex buffer for use over multiple frames for each string to be rendered would be the fastest, so long as the text on the screen isn't constantly changing every frame, because with most font-rendering setups it may as well be (including mine) what with the redundant re-submission of text to be rendered being sent to the GPU every frame.

##### Share on other sites

Thanks for all of your replies.

Well my idea with the tesselated fonts started when I was imagining a game where test was more important than usual. Not walls of text like in some RPGs, but where you have small parts of text that are important.

Maybe I will try to write a small benchmark some day, to find out how much it does cost. Since tesselated glyphs have between a few and a few hundred glyphs I imagine it would be difficult for languages that have complex glyphs to stay in budget.

Since most of you are using some preprocessing stage, I do have some more questions:

8. Do you just include all of the glyphs in a font or do you use only a subset?

9. How do you handle stuff like ligatures and other advanced features? What about Right-to-left? Do you handle all of that stuff yourself, do you let the OS do it's thing or do you just not support it?

10. How open is your system, e.g. if your game supports modding, are mod makers limited to the language and font you selected or is it possible to choose another font and write text in languages your own game does not nativly support?

##### Share on other sites

My in-progress system uses Freetype to load/render the font glyphs at arbitrary sizes to a set of texture atlases. When rendering a string, I build a vertex buffer using textured quads for each glyph, then draw that vertex buffer.

As for glyph management, when rendering each character:

• Do hash lookup to find if the character's glyph is already present in one of the texture atlases for the font.
• If it's present and the size of the glyph in the texture is big enough for the currently rendered font size, the renderer uses the existing glyph image to texture a properly scaled and aligned quad.
• If the required glyph is not present, the renderer picks an available spot in a texture atlas and renders the glyph to that region of the texture using the largest size that can fit in one of the texture atlas's slots. The glyph texture can then be used as described above.
• Texture atlases are stored as 8x8 (because 64 characters is mostly enough for ASCII text) grids where each grid slot is a power of two sized square region of the texture. For a glyph whose bounding box is at most 16x16 pixels, it will be placed in a texture atlas with 8x8 = 64 slots of size 16x16. When an atlas is full or different size is necessary, a new one is created. The renderer has to make sure to split up strings that require different atlases into different rendering calls. In practice, this doesn't happen very much for most scripts.
• Kerning information for adjacent character pairs is retrieved directly from the freetype font during rendering.

The result of this system is that only the glyphs (at the proper size) that are actually needed are cached from the font in the texture atlases.

##### Share on other sites

Textured quads with distance fields. This works very well for both scaling up and down, and you can nicely antialias at any scale (plus, special effects if you want). Shaders are well-documented in several papers and readily available with liberal licenses, so implementing it is not all that hard. Performance is almost identical to using normal textured quads on modern GPUs.

Tesselated outlines are forbidding if you need to render more than a few dozen characters in real time.

Signed distance fields is a great approach if you want an effective way of rendering multi-scale fonts, including bold, italic, light etc. all from the same font texture. A good video of some of the results can be found here: http://www.youtube.com/watch?v=CGZRHJvJYIg, and Bitsquid have very kindly made a generator from font file available here: http://bitsquid.blogspot.com/2010/04/distance-field-based-rendering-of.html

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627654
• Total Posts
2978447
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33