Text

Ways to draw text in OpenGL:




In all these methods, a basic idea is to create an array of objects - one for each possible text character - and to index the array using string characters during drawing.

This makes use of the facts that, in C & C++:

  1. a text string is an array of characters
  2. a character is equivalent to an integer (and hence can be used to index an array)

Pseudocode:

        fontDrawingData characters[MAX_CHARACTERS];

        drawString(char * string, int stringLength)
            {
            for (int i=0; i < stringLength; i++)
                {
                int charIndex = string[i];
                drawTextObject(characters[charIndex]);
                advanceDrawingPosition(characters[charIndex]);
                }





next