Sign in to follow this  
qCring

Fast fonts in ogl

Recommended Posts

Hello, everyone! This is no request for a how-to guide to write a good font-engine. I´ve implemented a small and simple font-engine in OpenGL using VBOs and it works well so far. But when I start my browser and scroll through hundreds of lines of text, I´m impressed how the application (Mozilla for example) handles so much information with no signs of cost... Since I compared the handling of text by the OS to my hardware-accelerated font-engine, I´m wondering if there is a better way of doing that... Can I use the OS to display fonts on top of my openGL app? Or is there a better way of displaying 2D Fonts using hardware-acceleration than using VBOs? adios!

Share this post


Link to post
Share on other sites
I'm rendering the text (all the glyphs) into it's own texture before rendering to the framebuffer, so I don't have to redo it every frame. I'm assuming that's something "everyone" does, but I don't know since I've never read anything on the subject.

Share this post


Link to post
Share on other sites
ok, that´s a good point. I didn´t optimize anything, that´s true. So every glyph is rendered every frame in my case. I know about these issues. But it seems to me that the way of font-rendering via VBOs is a slow process in general compared to the os' way of doing that. Plus there would be other nice advantages if that service could be used from the os.. things like dynamic coloring and font style and different sizes ( I can´t do that by using one static texture to map the glyphs to quads with the same quality )...

Share this post


Link to post
Share on other sites
When Microsoft announced the better D3D-OS interoperability, I seriously hoped that some serious text solutions would have been provided. So far, the only thing that looks somewhat useful to me is DirectWrite, which is a Win7 exclusive... and I still miss the ability to arbitrarly position the text in the 3D world as far as I've understood.
For OpenGL, you're on your own.
This is terrible.

I cache the glyphs outlines (not characters!) and resulting tassellation on a "normal size", adapting on need. Although my system would surely break with a very long text, I am confident it could scale to hundreds of (admittedly short) lines.

If you're using the "textured quads" approach, be warned that as soon you go out of your codepage, it'll probably won't work as expected. As far as I've understood what Grantax is doing is what's commonly used. You may want to check out FreeType for glyph rasterization when rasterizing the texture. Keep in mind however that FreeType is glyph-based, and the only multi-glyph thing it does is providing support for kerning pairs. General Unicode text can be far more complicated.

Share this post


Link to post
Share on other sites
Qt has an impressive painting engine which has also an OpenGL back-end. Text rendering is very fast and I think it supports shader based anti-aliasing. We are currently using it for text rendering in our engine. We use the label widget to display text which supports HTML (or maybe a subset of it) and is thus very flexible.

Share this post


Link to post
Share on other sites
We're using cairo/pango. Cairo does general drawing management, pango does text formatting for it (including international stuff). Underneath it uses freetype for some of the work.

Cairo's output is a 32 bit canvas which conveniently can simply be uploaded as a texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by Katie
We're using cairo/pango. Cairo does general drawing management, pango does text formatting for it (including international stuff). Underneath it uses freetype for some of the work.

Cairo's output is a 32 bit canvas which conveniently can simply be uploaded as a texture.

I used cairo for svg rendering, but I had to change to freetype because of a big problem. The problem I had with cairo was that it seemed to ignore the alpha value of the surface it rendered onto (I considered it to be opaque):

I had an "empty" surface (color rgba(0, 0, 0, 0), that's 100% transparent "black"). I then rendered rgba(1, 1, 1, 0.5) all over it. In my head, the new color should be a 50% transparent white color. Yet in cairo, it was rendered as a 50% transparent gray color (50% white mixed with 50% black background).

None of cairo's blending methods seemed to solve this problem. Have nobody else noticed this, or am I doing something wrong?

Share this post


Link to post
Share on other sites
Quote:
Original post by Grantax
None of cairo's blending methods seemed to solve this problem. Have nobody else noticed this, or am I doing something wrong?


Look up pre-multiplied alpha. This is what Cairo is using, as far as I can tell.

Share this post


Link to post
Share on other sites
ok thanks alot for all your advices! Basically I was inspired by the way apps like blender managed to display their UI so I wanted to implement all that fancy UI stuff with OpenGL. Now I´ll try to use the MFC to get things done. Let´s see how easy/hard it is to make a nice looking UI based on OpenGL but take the advantage of text-rendering from the os side... It´s a pity that WPF comes along with only C#/VB.. It has great potential when it comes to GUI-stuff. But no WPF for good ol´ C++/OpenGL programmers, right :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this