Reputation: 1017
Given that neither OpenGL nor Direct3D support high-quality font rendering (such as LCD rendering), how do toolkits which render their UIs using one of these hardware graphics APIs manage to integrate such quality text within a 3D or 2D "scene"?
Are they calling platform-specific APIs (such as DirectWrite on Windows) to render the text into some kind of image buffer which is then displayed in the scene (maybe as a texture or whatever else is available)?
Upvotes: 2
Views: 1515
Reputation: 98505
All text rendering in Qt 5, so far, always starts with the CPU-based raster backend.
In Qt 5, there are three text rendering modes:
QWidget
- raster backend output is used directly, there's no hardware acceleration.
QOpenGLWidget
- the raster backend renders to a texture (perhaps a font atlas), the texture is then displayed on triangles. Zooming in causes obvious pixellation.
Qt Quick (in QML) uses Valve's Signed Distance Field text rendering, and is done on the GPU based on a precomputed distance field texture. The texture comes from the raster backend, but doesn't directly represent the text you see.
The SDF representation allows cheap text styling - outlines, glows and drop shadows are computed by the GPU as well, based on the same texture.
See this blog entry for details of Qt's implementation.
See this comparison video between the three.
There are much better approaches now, where the rasterization is done completely on the GPU using an outline font representation of a string of quadratic splines. As with all good things, the problem is that some of those methods are patent-encumbered :( They do allow for easy addition of effects such as outlines.
See this webgl/javascript War and Peace reader (sic!) implementation that adaptively switches between GPU rasterization (at glyph sizes above a dozen pixels or so) and a font atlas (at smaller sizes) to render 1300 pages of text at realtime frame rates.
See this webgl/javascript equation renderer for not only realtime rendering of text, but also realtime rendering of math equations, even those without closed-form formulas. As it turns out, you don't need closed-form formulas to draw as-if there was a closed-form formula :)
Upvotes: 1
Reputation: 162297
Usually they use a glyph rasterizer and text layout libraries that run on the CPU to render whole paragraphs of text into a picture. That picture is then loaded to the GPU where it's drawn at the desired place.
A number of people (including me) are working on GPU accelerated all-purpose glyph rendering, that doesn't rely on a lot of preprocessing. There are a number of interesting approached which got published over the past few years, but no gold-standard solution so far.
Upvotes: 1