Advertisement

Font rendering

Started by February 07, 2017 06:28 PM
23 comments, last by penguinbyebye 7 years, 6 months ago
I'm using D3D9 still. After a lot of messing with quad rendering, I finally profiled ID3DXFont and found it perfectly performant, even for a 10 line in game console.

i was using dx9 d3dxfonts, and was drawing text with drop shadows (IE 2-4 shadow draw calls, then the colored text).

the popup debgging HUD eventually displayed so much info that the fonts affected FPS (1.3ghz, onboard laptop GPU) - almost a whole screen of text drawn 5x . so i switched to sprites for fonts. MUCH faster. a single quad per character. 32x32 texture maps for each character drop shadows are included in the textures, so only one draw call each. No atlas-ing yet. made it work in both 2d sprites and 3d quads. so i can do both 2D UI text and 3d text in the game world.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Personally I really like the style from tigr. It contains a custom font image where each character is bordered by a consistent color. The border color is determined at run-time by looking at the bottom right pixel of the image. Then, by using the border color to define character boundaries the width of each different glyph is determined on font-load. Glyphs are then mapped from ascii/UTF-8 indices to sprites, where each sprite is defined as a UV pair that offsets into the font image.

Advertisement

It is just difficult to grasp, that programs like Blender suffer on models of 10M triangles, whereas a screen full of text characters would be no problem.


Triangle counts are not usually the big bottleneck these days. Not by a long shot.

The complexity of the shaders, the amount of overdraw, and other more esoteric concerns (how small the triangles are) matter a lot more. Blender is rendering a complex 3D scene via its tris, not simplistic bitmapped text glyphs.

Rendering a screenful of text might only be 400 x 300 quads, e.g. 240,000 triangles. Which is only a teensy tiny fraction of how many tris your hardware can push out in its lowest active power mode; a game's main character might have that many (or more) tris these days. Especially if you're smart about batching, texture reuse, etc.

Sean Middleditch – Game Systems Engineer – Join my team!

Something else you can do is generate a set of 3D meshes of characters from a font, e.g. using the blender text tool, then use those to draw 3D meshes of text in 3D space, at any scale you want without loss of resolution or quality.

You can even instance up the draw calls of the characters when you output strings.

I've used this in two of my Unreal games to generate 3D huds and widgets.

What are your thoughts on this?

the width of each different glyph is determined on font-load.

proportionally spaced font? doesn't that make calculating string width in pixels a pain?

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

the width of each different glyph is determined on font-load.

proportionally spaced font? doesn't that make calculating string width in pixels a pain?

Generally strings are encoded in UTF-8 for localization, which means computing string length would be a O(n) operation anyway. In my game computing string lengths only occurs as strings are being drawn, in which case an O(n) loop is being used to convert characters to glyphs anyways. Plus, the font can be created with fix-width if desired (mine actually is, even though the code does not assume fixed width).

Advertisement
On 2/8/2017 at 1:07 AM, formerly_known_as_samoth said:

For those unaware, while we're at "rendering text", I'd like to use the occasion to point out this guy's technique which I stumbled upon a few months ago:

http://wdobbie.com/post/gpu-text-rendering-with-vector-textures/  (live demo: http://wdobbie.com/pdf/)

What's special about it? He stores the actual bezier curves (splitting cubic ones into several quadratics) in a texture buffer and renders them in realtime in the fragment shader, with supersampled antialiasing. Which is just fffffffffffffffucking awesome quality, irrespective of how far you zoom. What's the most stunning, it isn't even painfully slow. You would think it's crawling, but it's not.

 

I only wish there were tools available to convert any TTF font, too...

Back in December, I started playing around with new font rendering techniques, and I ran into some serious numerical robustness issues with the above method. You can see some of the problems in this Twitter thread:

I spent about a month full-time trying to make it work, but failed over and over. I could fix some artifacts, but doing so would always introduce others. There is simply no way to make this approach work cleanly for all fonts, sizes, etc., due to the finite precision of floating-point operations and the manner in which the technique determines whether a pixel is inside the glyph or not.

So I started doing some R&D and came up with a new method that I've now turned into this product:

http://sluglibrary.com/

It is 100% robust for all possible inputs, it's about 8 times faster than the above method, and it doesn't have the glyph complexity limits that the above method has.

To my knowledge, this is the only production-ready solution for rendering text directly from glyph outlines, and it has arrived right as GPUs are becoming powerful enough to justify it and right as higher-DPI displays are becoming common enough to create a need for it.

And there's even a conversion tool so you can try out any TTF font.

1 hour ago, Eric Lengyel said:

To my knowledge, this is the only production-ready solution for rendering text directly from glyph outlines, and it has arrived right as GPUs are becoming powerful enough to justify it and right as higher-DPI displays are becoming common enough to create a need for it.

Now we just need a cheap indie licensing option :)

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

2 hours ago, swiftcoder said:

Now we just need a cheap indie licensing option :)

What would you consider "cheap" for an indie commercial product?

(The library is already free for noncommercial use.)

7 hours ago, Eric Lengyel said:

What would you consider "cheap" for an indie commercial product?

(The library is already free for noncommercial use.)

Generally any product that doesn't advertise a price will be assumed to be unaffordable by us common folk ("if you have to ask the price, you can't afford it" is the common saying)...

A decent sized indie game might be 5 people for a year, which would have <$10k engine licensing costs with Unity, or $10k-$30k licensing costs with Unreal. These people would buy your library as a plugin from the Unity/Unreal asset stores... On the other hand, if they're building their own tech, they're probably doing so in an effort to save that $10k on engine licensing and will therefore only have a few thousand total to throw at all the middleware required to produce an ad-hoc engine. Unless their game is all about beautiful text specifically, it's probably hard to get those kind of people to pay anything for a font renderer when the free alternatives work well enough for most situations... So "cheap for indies", would probably mean something like "free per game if you release one game per year and have per anum revenue or game budget of under $250k", etc... :|

This topic is closed to new replies.

Advertisement