
Whenever you want to render a character, you select the corresponding glyph by rendering this section of the bitmap font to a 2D quad. Each glyph has a specific region of texture coordinates associated with them. These character symbols of the font are known as glyphs. Such a texture, that we call a bitmap font, contains all character symbols we want to use in predefined regions of the texture. In the early days, rendering text involved selecting a font (or create one yourself) you'd like for your application and extracting all relevant characters out of this font to place them within a single large texture. In this chapter we'll explore several methods and implement a more advanced, but flexible technique for rendering text using the FreeType library. Rendering textured quads by itself shouldn't be too difficult, but getting the relevant character(s) onto a texture could prove challenging. Most developers choose to render character textures onto quads. Some example techniques are: drawing letter shapes via GL_LINES, create 3D meshes of letters, or render character textures to 2D quads in a 3D environment. There are no graphical primitives for text characters, we have to get creative. Since there is no support for text capabilities within OpenGL, it is up to us to define a system for rendering text to the screen. Based on where you live, you may also need more than 128 characters, and what if you want to express special symbols for like mathematical expressions or sheet music symbols, and what about rendering text from top to bottom? Once you think about all these complicated matters of text, it wouldn't surprise you that this probably doesn't belong in a low-level API like OpenGL. Things are getting difficult as soon as each character has a different width, height, and margin. If you don't care about rendering more than 128 different same-sized characters, then it's probably not too difficult. Contrary to what you may expect, getting a simple string to render on screen is all but easy with a low-level API like OpenGL. Text Rendering In-Practice/Text-RenderingĪt some stage of your graphics adventures you will want to draw text in OpenGL.
