Help end child hunger

VSFontLib Specification

Prev: Header Next: Header

To use the lib you have to include vsFontLib .h. In all the examples below it is assumed that vsfl is an instance of VSFontLib.

VSFontLib vsfl;

Class Initialization

bool loadFont(std::string fontName)

Load a font. This function assumes that there are two files for each font, where both share the same name, one containing the image with the chars (extension tga) and another with the texture coordinates and other information required to properly render strings (extension xml). These files were generated with FontStudio, see the main page of VSFontLib.

The parameter is the name of the files without the extension.

The return value indicates if loading was successful.

Example assuming that the font is defined by the files couriernew10.xml and couriernew10.tga, and used them as fixed size:


To use the font with optimal individual char length just do


setFixedFont(bool isFixed)

If using a fixed size font, the spacing is set in a different form. Calling this function makes sure that the characters are properly spaced.


Sentences are processed strings ready for rendering.

unsigned int genSentence()

VSFLFont adopts a strategy very similar to OpenGL. For each string that we want to render we must first create a slot. This function returns the index of the allocated slot. The index is required for the next steps.


GLuint aSentence = vsfl.genSentence();

void deleteSentence(unsigned int aSentence)

Frees VAO and vertex buffers allocated for the sentence.



void prepareSentence(unsigned int index, std::string sentence)

Receives an index for a previously allocated slot (with genSentence) and a string. It creates a VAO with the vertex buffers containing the vertex and texture coordinates, using the attribute locations for these two attributes (see setVertexAttribLocs).

If the string includes a char that is not part of the font definition then that char is skipped. A newline (‘\n’) is a valid char and it causes the vertex coordinates to drop a line, where a line is the number of pixels for the font height, as defined in the xml file.


GLuint aSentence = vsfl.genSentence();
vsfl.prepareSentence(aSentence, "Display this\nand this");

void renderSentence(int x, int y, unsigned int index)

Renders the string stored in slot index, starting at the position (x,y) in window coordinates. The origin is the top left of the window.

This function builds projection and modelview matrices that provide a 1:1 mapping between pixels in the window and pixels in the texture that contains the font chars. Rendering is performed with the VAO previously created with prepareSentence. Users must call glUseProgram with the program shader intended for string rendering sometime prior to call the renderSentence function.

Example assuming that p is the program shader used to render the string:


void renderAndDiscard(int x, int y, std::string aString)

This function is a shortcut for when a string is rendered only once. Calling

vsfl.renderAndDiscard(10,10,"Display this");

is equivalent to:

unsigned int s = vsfl.genSentence();
vsfl.prepareSentence(s, "Display this");


Prev: Header Next: Header

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 Suffusion theme by Sayontan Sinha