9.1. What i have to do to print some text?

There are several steps to initilize the library and setup some necessary paramaters. First at all we need to initialize the library and some of the external librarys they are needed to create some chars.

This will initialize the library at first. After this they try to load the OpenGL and GDI library. The OpenGL library will be used to draw texts. And the GDI library will be used to create some fonts under Windows. You also can one of the other librarys so far.

if tsInit(TS_INIT_TEXTSUITE) = TS_FALSE then
  // failed

if tsInit(TS_INIT_OPENGL) = TS_FALSE then
  // failed

if tsInit(TS_INIT_GDI) = TS_FALSE then
  // failed

If the initializing is done we have to create and bind an context. In this context all objects will be placed. This is similary to an OpenGL context. If we create an context it will be bound immediately. So its not necesarry to do this by hand.

var
  ContextID: tsContextID;

tsContextCreate(@ContextID);

The context is still really empty so we need to setup some properties. One of these properties is the used renderer. This can be set with the parameter TS_RENDERER and it will be used to save and draw the generated glyphs. Another important property is the current creator. They will be used to create then balnk glyphs they will transfered to the renderer. You can set the creator with the parameter TS_CREATOR.

tsSetParameteri(TS_RENDERER, TS_RENDERER_OPENGL);

tsSetParameteri(TS_CREATOR, TS_CREATOR_GDI);

After you have set these parameters you should be able to create an font. To create an font you need to call tsFontCreateCreator with the name, size, style aso as parameters. If you want to use the font later you must bind it with tsFontBind. But for the fonts apply the same as for context. After creation it is actual bound. So no manual binding necessary.

var
  FontID: tsFontID;

tsFontCreateCreator('blah.ttf', 18, TS_STYLE_NORMAL, TS_DEFAULT, TS_DEFAULT, @FontID);

Now we have one active and bound font and we can start to print some texts. In our OpenGL part we need to set an position. After this we can print text.

glTranslatef(200, 200, 0);

tsTextOut('This is just a little test.');

When you have finished your application and it's getting closed you also should frees all objects and finish the library. You can delete every small object but it's necessary if you delete your context. All object they depend on the context will be automatically destroyed.

tsContextDestroy(ContextID);
tsQuit();