2 and 3D Fonts
These two simple classes wrap wglUseFontBitmaps and wglUseFontOutlines, respectively. Their interfaces are
small - a method to specify font face and other parameters, and method(s) to draw a string.
A few notes on Windows GL fonts not specific to these classes:
2D Fonts: The position at which the first character of the string is rendered is controlled with the GL command
glRasterPos. You can position the text in 3 - space with the glRasterPos3f version. However, if the raster position is out of
the viewing frustum, the text will not be rendered. This means if you have a string that is only partly within the frustum, and
the right hand portion of the string is outside the frustum but the raster position is inside, the text will appear, and will be
clipped at the viewing volume. If, however, the left - hand portion of the string is outside and the right - hand portion is inside
the frustum, no text will be rendered because the initial raster position was invalid.
The currently selected color is latched into the Raster Color state variable when glRasterPos is called.
So, if you want your text to appear a certain color, set the color BEFORE calling glRasterPos. Also, if you're using
lighting, the color the bitmaps are painted is affected by the last set of material/lighting calculations performed. This
can have unexpected effects. To ensure the selected color is the one used, disable lighting before drawing the text, and
re-enable it after.
One nice thing about 2D text is that you can create text of any size without using glScale. There are none
of the performance penalties involved in using 3D text in various sizes.
3D Fonts: Windows doesn't allow the creation of various size 3D font objects in GL, so to change font sizes you
must use glScale. The problem with that is that normal vectors aren't adjusted, so lighting calculations don't work
correctly. To counter this effect, you must enable automatic normal vector normalization with glEnable(GL_NORMALIZE).
And, as you might expect, this is computationally expensive. ( OpenGL 1.2 offers a potential way around this problem. If the
scaling is uniform in all 3 axes, a new glEnable mode, GL_RESCALE_NORMAL, can be used. It uses a mathematical shortcut
to eliminate much of the performance penalty incurred when performing true normalization.)
A point worth noting is the use of the 'Deviation' parameter on rendering speed. All examples I've seen elsewhere
demonstrating 3D fonts on the WIN32 platform (Platform SDK and elsewhere) use a value of zero for this parameter.
This results in massive over-tessellation of curved surfaces. Increasing the Deviation limit will dramatically
speed up rendering, but will degrade the fidelity with which the font is reproduced in 3D. In all likelihood a Deviation value
of 0.2 ~ 0.4 will yield acceptable quality text and a rendering rate several times greater than would have been achieved
with the Deviation equal to zero.
|