Author Topic: TrueType font rendering  (Read 46374 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
TrueType font rendering
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: [Select]
#Fonts
<font entries>
#End

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: [Select]
$Font: font01.vf
  +Name: Font 1

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: [Select]
||+Top offset||
  <line of text>
||+Bottom offset||
||+Top offset||
  <line of text>
||+Bottom offset||
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: [Select]
$TrueType: arial.ttf
+Name: Arial
+Size: 12

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: [Select]
#Fonts

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

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

#End

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
« Last Edit: July 24, 2015, 10:32:50 am by m!m »

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: TrueType font rendering
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: [Select]
$TrueType: Bankgothic.ttf
+Size: 10

$TrueType: Bankgothic.ttf
+Size: 20

$TrueType: Bankgothic.ttf
+Size: 32

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.
« Last Edit: November 16, 2011, 10:52:59 am by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: TrueType font rendering
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.
« Last Edit: November 16, 2011, 08:46:53 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Swifty

  • 210
  • I reject your fantasy & substitute my own
Re: TrueType font rendering
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.

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: TrueType font rendering
Hmm, wonder if we could convert VF to TTF on the fly and eliminate the need for the immediate mode renderer.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: TrueType font rendering
id just have some font guru htl* the **** the current fonts. procedurally converting raster fonts to vector fonts, not so easy, and would probably look like crap.


*yes im using the term incorrectly. bite my fleshy meatbag ass!
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: TrueType font rendering
Well, the main issue is that there are mods already released with their own fonts.  If we could be certain we found all existing fonts, that might work, otherwise I'm not sure how we could avoid breakage.  Could deprecate older fonts perhaps.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: TrueType font rendering
Well, I think what we could do is convert those little graphics to ppms and include them in the source, with possible override via little pngs or something.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline m!m

  • 211
Re: TrueType font rendering
I updated the patch link with a new patch to an updated version where fonts with no special name get a more unique generated name. I also attached a patch against antipodes which only contains build file changes.

I also think that adding bitmaps for those special characters is the best solution as that would also make further customization of the various HUD options possible.
« Last Edit: November 21, 2011, 01:00:39 pm by m!m »

 

Offline m!m

  • 211
Re: TrueType font rendering
The issue with the spaces in the briefing text should now be fixed, updated links to patch and test builds download. Again a patch against Antipodes is attached.

[attachment deleted by a basterd]

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
Re: TrueType font rendering
2011 is now officially The Year of Awesome SCP Additions that Came out of Nowhere. :D

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: TrueType font rendering
As well as Additions We Hoped To Release This Year But Probably Won't Get to Until Next Year.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: TrueType font rendering
As well as Additions We Hoped To Release This Year But Probably Won't Get to Until Next Year.
Isn't that every year ?
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline headdie

  • i don't use punctuation lol
  • 212
  • Lawful Neutral with a Chaotic outook
    • Minecraft
    • Skype
    • Twitter
    • Headdie on Deviant Art
Re: TrueType font rendering
As well as Additions We Hoped To Release This Year But Probably Won't Get to Until Next Year.
Isn't that every year ?

I would say so and tbh I am just glad for the features, bug fixes and optimisations we have been given
Minister of Interstellar Affairs Sol Union - Retired
quote General Battuta - "FRED is canon!"
Contact me at [email protected]
My Release Thread, Old Release Thread, Celestial Objects Thread, My rubbish attempts at art

 

Offline m!m

  • 211
Re: TrueType font rendering
Tab characters are now "drawn" correctly and the width of these can be adjusted. First post has been updated with some documentation about the new option and has new links to the test builds and the patch.

 

Offline m!m

  • 211
Re: TrueType font rendering
I added a feature which lets the modder specify a spacing option for every drawn line so you can space out the lines of a text without having to change the font itself. First post has been updated with new links to the patch and test builds and I also added information about the added features.
ATTENTION: The patch was created against the Antipodes branch and the provided test builds are also Antipodes builds which include the new pilot code.

 

Offline AndrewofDoom

  • In A.D. 2366 war was beginning
  • 29
  • Permanent yuri goggles.
    • Skype
    • Steam
    • Twitter
Re: TrueType font rendering
Both links are the same fyi. You may want to fix that.
My Efforts:
SF Knight

20:08:19   AndrewofDoom: Though I find it mildly disturbing that a loli is giggling to mass destruction.
20:10:01   Spoon: I find it mildly arrousing
20:10:07   AndrewofDoom: Woah
20:10:15   Spoon: sound like my kind of loli
20:10:21   Spoon: and im not even a lolicon

 

Offline m!m

  • 211
Re: TrueType font rendering
 :mad: :banghead: :snipe:
Fixed...
EDIT: The last build broke Hud_gauges.tbl parsing, new build has been uploaded...
« Last Edit: January 30, 2012, 08:17:32 am by m!m »

 

Offline AndrewofDoom

  • In A.D. 2366 war was beginning
  • 29
  • Permanent yuri goggles.
    • Skype
    • Steam
    • Twitter
Re: TrueType font rendering
So I tried it out, and it's very cool. But, has anyone tried to go to the ship selection in the briefing? It seems to CTD for it me when I do that...
My Efforts:
SF Knight

20:08:19   AndrewofDoom: Though I find it mildly disturbing that a loli is giggling to mass destruction.
20:10:01   Spoon: I find it mildly arrousing
20:10:07   AndrewofDoom: Woah
20:10:15   Spoon: sound like my kind of loli
20:10:21   Spoon: and im not even a lolicon

 

Offline m!m

  • 211
Re: TrueType font rendering
Hmm, doesn't happen on my side. Can you generate a debug log?