Bright Ideas Software - Calculus Visualization Tools Click here to return to the BIS Home Page.

GLE32 Ver. 4 Manual

  Skip Navigation Links
Math ToolsExpand Math Tools
DevelopersExpand Developers
About BISExpand About BIS
  Skip Navigation LinksHome --> Developers --> GLE32 Version 4 --> GLE32 Manual --> 2D and 3D Fonts Search:
Skip Navigation Links

Skip Navigation Links

OpenGL® and OpenGL|ES are trademarks of Silicon Graphics, Inc.




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.


Font Utilities

Function

  

Description

HFONT gleCreateFont(HDC hdc, char* strFaceName, int iPoint, int iAttributes)  iAttributes is the bit-wise OR of GLE_FONT_ATTR_BOLD, GLE_FONT_ATTR_ITALIC, GLE_FONT_ATTR_UNDERLINE and/or GLE_FONT_ATTR_STRIKEOUT.

Cgle2DFont

Methods

  

Description

 Cgle2DFont ()   
 ~Cgle2DFont ()   
BOOL FromFont (HFONT font, HDC dc)  Creates the bitmap font from the font handle passed here. Note that the device context must have a valid rendering context selected into it at the time.
void ReleaseResources()  Release the GL display list.
void Draw (TCHAR* text)  Renders the string at the current raster position.

Cgle3DFont

 Cgle3DFont ()   
 ~Cgle3DFont ()   
BOOL FromFont (HDC dc, HFONT hFont, float Deviation, float ExtrusionDepth)  Creates the outline font objects from the font handle. Note that the device context must have a valid rendering context selected into it at the time. See notes above re: Deviation.
void ReleaseResources()  Release the GL display list and GLYPHMETRICS array.
void GetStringSize (char* Text, float* XYZ)  This will return the height, depth and width of the string, in GL units.
void Draw (char* Text)  Draw the string with solid polygons.
void WireDraw (char* Text)  Draw the string with wireframe polygons.

Back To Top



Copyright© 2001-2010 by Bright Ideas Software®. All rights reserved.