Thankfully we implemented a rather nice font engine in Flare, and it will be coming over to S3.
The top-level API exposes a method to create a Typeface(an alias an image and widths file pair)
once loaded a typeface is immutable undestroyable for the lifetime of the engine session, any attempt to load a typeface with the same alias of an existing typeface will be ignored and the existing typeface will be unchanged.
these restrictions are for performance sake.
when a part of the engine wants to some drawing, it creates a Font object.
a font object consists of:
A typeface reference
The creation of the font object uses the typeface alias to resolve the typeface reference.
since the engine is only accessable through the script interface, the script api defines functions for setting certain fonts to certain areas of the engine, such as:
as each one of these systems are processed they set their own fonts before they draw their text.
on the engine side when a font is set it's reference is held and used for every call to:
the rendering engine supports left,hcenter,right alignment and supports word wrap and character clipping.
text in the s3 engine is primarily used for some radial menu items, info text (stuff your mouse is over) and Dialogue, in many cases the engine can override parts of a font, for instance:
if no desired dialogue color is set for a character, then it will use the default color (narrator color) otherwise the speaking character's color is set to it.
Text is rendered in batches of fonts, a TextBatch object references the font, and keeps a copy of the text to be rendered, the font rendering engine then converts the text and the font into a serries of quads which are added to a dynamic vertex buffer.
an important restriction is that no more than 256 characters of text per-font, given the text usages in S3 this is not a big deal.
the restriction allows for easy use of indexing, a 256*6 element 16 bit index buffer is used to reference the vertex buffer, which can now be much smaller, and potentially utilize the vertex cache.
the basic rendering loop looks somthing like this
set vertex buffer
set index buffer
set text shader
baseIndex = 0
for each TextBatch
set font texture
set font color
draw indexed primitive baseIndex,all of the primitives in this batch
baseIndex+=number of indexes we drew
set null index buffer
set null vertex buffer