Fonts and Text (OpenGL)
Microsoft's implementation of OpenGL in Windows supports GDI graphics in a single-buffered OpenGL window. It does not support GDI graphics in a double-buffered OpenGL window. Thus, you can call only the standard GDI font and text functions to draw text in a single-buffered OpenGL window; you cannot call those functions to draw text in a double-buffered OpenGL window.
There is a workaround for this restriction on text in double-buffered windows: build OpenGL display lists for bitmap images of characters, and then execute those display lists to draw characters. There are three main steps in this process:
- Select a font for a device context, setting the font's properties as desired.
- Create a set of bitmap display lists based on the glyphs in the device context's font, one display list for each glyph that the application will draw.
- Draw each glyph in a string, using those bitmap display lists.
To create the display lists, call the wglUseFontBitmaps and wglUseFontOutlines functions. To draw characters in a string using those display lists, call glCallLists.
To create applications that are easy to localize and that use resources sparingly, the creation and storage of these glyph image display lists must be managed carefully. Many languages, unlike English, have alphabets whose character codes range over a relatively large set of values.
Related topics