Jump to content

  • Log In with Google      Sign In   
  • Create Account


font rendering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 shadowomf   Members   -  Reputation: 315

Like
0Likes
Like

Posted 20 January 2013 - 06:30 AM

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.

 



Sponsor:

#2 Geometrian   Crossbones+   -  Reputation: 1432

Like
2Likes
Like

Posted 20 January 2013 - 09:29 AM

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.


And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

#3 ziashan   Members   -  Reputation: 108

Like
0Likes
Like

Posted 20 January 2013 - 12:54 PM

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).



#4 samoth   Crossbones+   -  Reputation: 4528

Like
3Likes
Like

Posted 20 January 2013 - 01:06 PM

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, 20 January 2013 - 01:07 PM.


#5 radioteeth   Prime Members   -  Reputation: 920

Like
0Likes
Like

Posted 20 January 2013 - 01:11 PM

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

2. textured quads

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.



#6 shadowomf   Members   -  Reputation: 315

Like
0Likes
Like

Posted 21 January 2013 - 12:59 PM

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?



#7 Aressera   Members   -  Reputation: 1317

Like
1Likes
Like

Posted 23 January 2013 - 09:31 PM

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.



#8 dougbinks   Members   -  Reputation: 479

Like
0Likes
Like

Posted 24 January 2013 - 03:08 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS