Tutorial #2 - Printing


FontLib has four functions to facilitate printing, fontBind, fontPrint, fontFlush and fontUnbind. This tutorial will cover printing using the default behaviors. The third tutorial will cover different states.

fontBind prepares OpenGL by binding the texture and setting the OpenGL state machine.
fontPrint loads vertex arrays into a vector only.
fontFlush sends the vertex arrays to OpenGL. This allows one write for several calls of fontPrint.
fontUnbind returns the OpenGL state machine to it's prevous state.


Fontlib requires that you call:
void fontInit()

before calling any other functions.

The next step would be to load the font we're going to use, using.
bool fontLoad(char* ImageData, char* WidthData, char* name1, char* name2);

For this example, I'll assume I generated a MSSerf & Terminal Font.
fontLoad("MSSeirfTerminal.tga","MsSerfTerminalData.dat","MsSerf", "Terminal");

I could use anything for "MsSerf" or "Terminal" under 10 characters, such as "DialogText" or "Scream", but I'll keep it simple for the example.


1. Bind the texture and font using fontBind
2. Save your messages using fontPrint. You can print multiple times without sending anything to the screen.
3. fontFlush puts the messages stored in fontPrint onto the backbuffer. You may continue to print and flush as many times as you'd like
4. when you're finished printing, call fontUnbind to return to rendering.

Sample code:
fontPrint("Hello World", -10, -10, 0, 0.4);

Sample code

Sample 1