OpenGL character Functions The OpenGL Base Library provides basic support for displaying single characters and text strings only. We can define the bitmap characters in Figure 3.61 and store a bitmap set as a font. A text string that maps a sequence of bitmaps selected from the font to the frame cache.
Adjacent locations to display.
However, there are predefined fonts in the
OpenGL utility Function Toolkit (GLUT) . So we don't have to create our own bitmap font libraries unless we need to display fonts that are not in glut. The GLUT sub-program displays bitmaps and outline fonts. Glut bitmap fonts are drawn by OpenGL's Glbitmap function, while outline fonts are generated by the polyline boundary (Gl_line_strip).
Use the following function to display glut bitmap characters:
Glutbitmapcharacter (font, character);
Here the parameter font is assigned a value using the glut symbol constant, which specifies a particular font set, and the parameter character is assigned the ASCII encoding or the character that he wants to display . In this way, to display the uppercase "a", you can use ASCII encoding 65 or specify ' a '. Similarly, encoding 66 is equivalent to ' B ', encoding 97 is equivalent to lowercase character ' a ', encoding 98 is equivalent to ' B ', and so on. Fixed-width or proportional-spaced fonts are available. You can use
glut_bitmap_8_y_13 or
glut_bitmap_9_by_15 to select a fixed-width font and determine its parameters. You can also
glut_bitmap_times_roman_10 or
glut_bitmap_helvetica_10 to select a 10-pound proportional spacing font. 12-pound
times-roman Fonts and 12-pound and 18-pound
Helvetica fonts are available.
The characters displayed with
Glutbitmapcharacter take the current raster position as its bitmap origin (lower-left corner). after the character bitmap is mounted to refresh the cache, the x-coordinate of the current raster position obtains an increment of the character width. For example, we can use the following program to display a text string that includes 36 bitmap characters.
Glrasterposition2i (x, y); for (k = 0; k < n; k++) glutbitmapcharacter (glut_bitmap_9_by_15, text [K]);
the string is displayed with the color specified before the Glutbitmapcharacter function is executed. use the following function to display an outline character.
Glutstrokecharacter (font, character);
In This function, we can assign a value
Glut_stroke_roman to the parameter font to display the font of the proportional space, or assign a value
Glut_stroke_mono_roman to display the font of the constant interval. The size and position of the character is controlled by specifying a transform operation before the Glutstrokecharacter subroutine is executed. After each character is displayed, the coordinate shift is automatically enforced so that the next character is displayed to the right of the current character. The text strings generated by contour characters are part of a two-dimensional or three-dimensional scene because they are composed of line segments. In this way, they can be observed in a variety of directions, are not deformed when they are scaled, and can be transformed in other ways. However, compared to bitmap characters, the drawing speed is relatively slow.
Computer Graphics (ii) OUTPUT elements _16_ character functions