Modding, Mission Design, and Coding > Test Builds

TrueType font rendering

(1/24) > >>

m!m:
I did some experimentations and I have a mostly working TrueType font rendering system for FSO. It uses NanoVG to render the font which is using Freetype to process the fonts.
Github branch: https://github.com/asarium/fs2open.github.com/tree/feature/ttf-nvg
Test builds: http://www.mediafire.com/download/cpie4xe49h28n6p/FSO-TTF.7z

Example mod: http://www.mediafire.com/download/3nymujuxfglnxrj/fontTest.7z

When could you be interested by this? This patch offers the ability to use TrueType which is a widely used font standard so you can use any TrueType font you can find for usage in FSO when using this patch. Other reasons why you may want to test this build:

* You want to use more than 5 interface fonts
* You want to have more control over the way the text is drawn
* You want to scale the font to different sizes at run-time
The patch only includes project file updates for Visual Studio 2010 so I would be grateful if somebody could give me an updated version of the project files for earlier versions of MSVS. I also got confirmation that an earlier version of this patch compiled and ran of Linux but it would be great if someone could confirm if this is still the case.
Warning: The patch was created against Antipodes and the test builds are also Antipodes builds

To use TrueType fonts you will first have to move the .ttf file into the data/fonts directory of you mod (create it if it doesn't exist) then you will have to edit the fonts.tbl table or if you don't have one then you can use the newly added -fnt.tbm modular table type.
General table structure:

--- Code: ---#Fonts
<font entries>
#End
--- End code ---

Old fonts can be specified with "$Font" and the filename of the font file. As the new system can also use names for identifying fonts instead of only indexes you can specify a name using "+Name" and some string value.
Example:

--- Code: ---$Font: font01.vf
  +Name: Font 1
--- End code ---

These fonts also support the "+Top offset" and "+Bottom offset" options which allow to specify a pixel-offset which should be applied before and after a line of text is drawn.

TrueType fonts can be added using the "$TrueType" option:
This option takes a filename of a TrueType font as its argument. Nothing more is needed for a basic setup, every following option is entirely optional.

You can again specify a name for easier identification using "+Name" like with the old fonts, if this option is not present then a name is generated (resulting in a name like "<filename>-<fontsize>"). The name has to be unique!

The next option would be "+Size" where you can specify the point size of this font which is the same as in every text editing program. Default is 8.

You can also specify a top and bottom offset for a TrueType font which can be set with "+Top offset" and "+Bottom offset". This will result in a line like the following:

--- Code: ---||+Top offset||
  <line of text>
||+Bottom offset||
||+Top offset||
  <line of text>
||+Bottom offset||

--- End code ---
This can be used to space out the lines of the fonts without having to change the font itself. The value for both options is given in pixels and the default value is zero in both cases.

You can use "+Tab width" to specify the width of tab characters. This width is given in multiples of spaces where 1.0 would be one space character. Default is 1.0.

The next option is +Letter spacing which can be used to change space between to letters.

+Special Character Font: This can be used to specify an old font file which should be used to draw special characters, you should only specify this if you know that you really need it.

Example:

--- Code: ---$TrueType: arial.ttf
+Name: Arial
+Size: 12

--- End code ---

I'd also be very happy if someone with better OpenGL knowledge could take a look at the rendering of these fonts as I'm a complete noob when it comes to OpenGL.

The sequence in which the fonts appear is also important. The first three fonts are used by FSO by default for interface rendering.

This patch also removes the fixed limit of a maximum of 5 fonts so you can now have an unlimited number of fonts.

This is a full example of a fnts.tbl file which includes the three default fonts and a TrueType font:

--- Code: ---#Fonts

$Font: font01.vf
$Font: font02.vf
$Font: font03.vf

$TrueType: arial.ttf
+Name: Arial
+Size: 12

#End
--- End code ---

I tested the patch but there may still be some bugs and/or visual inconsistencies so please test it and report those here.

I also took the liberty to change the "$Font" option in Hud_Gauges.tbl to also accept the name of a font as its value.

Regards,
m!m

The E:
Tested it, seems to work so far.

A few notes though:

1. The requirement that font names be unique is a bit troublesome, because it's not explained properly. I believe a tbl like this:

--- Code: --- $TrueType: Bankgothic.ttf
+Size: 10

$TrueType: Bankgothic.ttf
+Size: 20

$TrueType: Bankgothic.ttf
+Size: 32
--- End code ---

shouldn't cause trouble, yet it does. I think it would be more elegant if you used a combination of font filename and size as a temp name if no other name is given; that should keep things simple and transparent enough, imho.

Second note: Something with this new font code seems to interfere with the F3 lab, the UI code there doesn't really seem to like it. Given that that code is crap anyway, this is not that big an issue though, and I am confident that a solution can be found.

All in all, this is awesome work.

EDIT: Before I forget, can you provide a patch for this against the current Antipodes codebase? Given that AP is going to be merged into trunk soonish, it would be good to not have to convert it then.

EDIT EDIT: I may just be imagining things, but using TTF fonts may actually be faster than using FS2 fonts.....


EDIT EDIT EDIT:

Okay, here's a few more issues:


Spaces seem to be getting nommed in conjunction with coloured text


Several of the special characters used in the FS2 HUD are missing (no wonder, given that they are special characters created for those cases).
Note that, in addition, the red dots in the wingman display went AWOL; this hints at some strangeness happening in the HUD code.

Nuke:
cool, i can finally use smaller fonts for my scripted hud gauges.


first one looks like a simple parsing glitch.

the second one could probably be fixed with some kind of character replacement feature.

+replace: character index
+with: character index

you would still need to use a font with a similar symbol somewhere in the set. also this might screw up if you ever use a unicode font.

or you could just render those icons procedurally when using a ttf font.

Swifty:
Whoa! Awesome job, m!m! What libraries did you use to get the TrueType support? I always thought about integrating the FreeType library into FSO but never got around to doing that. From the patch, it looks like you're using FTGL?

I wouldn't be surprised if FTGL was faster than our font rendering setup. We still use immediate mode to render VF fonts and we don't even bother to batch them which something we could probably do since all characters are all in one texture map.

chief1983:
Hmm, wonder if we could convert VF to TTF on the fly and eliminate the need for the immediate mode renderer.

Navigation

[0] Message Index

[#] Next page

Go to full version