Font rendering

Started by
23 comments, last by penguinbyebye 6 years, 8 months ago

After reading a D3D11 tutorial about font rendering (http://www.rastertek.com/dx11tut12.html), I wonder if it is considered good practice to render each character from a texture to a separate quad (making an abstraction of font curves etc.)?

🧙

Advertisement

I wonder if it is considered good practice to render each character from a texture to a separate quad


I don't understand the question. You _must_ render individual quads (or points that expand to quads, or some GPU-driven conversion of a text string into quads), otherwise you couldn't get anything to show up in the first place.

Sean Middleditch – Game Systems Engineer – Join my team!

You _must_ render individual quads (or points that expand to quads, or some GPU-driven conversion of a text string into quads), otherwise you couldn't get anything to show up in the first place.

I wonder if one draws one separate quad for each character?

🧙

I didn't really like the approach in that tutorial for text rendering.

Instead I used a bitmap font renderer where each character is part of a texture with a known offset. It works very well and my game used to be built originally on those tutorials.

For example, see my blog post (which has in depth source code): https://www.gamedev.net/blog/1059/entry-2260816-making-my-own-spritefont-implementation/

Let me know if this helps! :)

Instead I used a bitmap font renderer where each character is part of a texture with a known offset. It works very well and my game used to be built originally on those tutorials.

Interesting stuff. I also do not need transform related stuff inside the font class itself but will just add a full transformation as for other geometry.

But I am going to take a look first at DirectXTK since I want to keep the number of lib dependencies as low as possible (<> d2d1.lib).

🧙

I wonder if one draws one separate quad for each character?


I still don't understand. I mean, yes, and that's what that tutorial does. Nothing shows up on screen where you don't render a triangle (or quad, etc.). You could render a single quad, but then you'd only be able to provide a single location on screen and a single set of texture coordinates, so you'd end up with just a single character on the screen.

One quad per character. You can use a texture atlas as others here are talking about to make it possible to use _instancing_ to render the quads, or to use a GPU vertex generation approach, but there will ultimately be one quad per character on the screen.

(There _are_ ways to use a single "coverage" quad for an entire input string, but those are advanced specialized cases that IMO are more novelty than anything.)

Sean Middleditch – Game Systems Engineer – Join my team!

One quad per character. You can use a texture atlas as others here are talking about to make it possible to use _instancing_ to render the quads, or to use a GPU vertex generation approach, but there will ultimately be one quad per character on the screen.

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.

🧙

<offtopic>

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...

</offtopic>

I feel the quads per character approach would be faster until maybe perhaps leaning toward screen height sized font because of sample fetch(ignoring insane texture memory at that extreme). Its neat to see a vector implementation but wonder if it would be worse at tiny font sizes.
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.

YMMV of course, but it is so much simpler. No idea if such a thing exists in 11/12 etc.

This topic is closed to new replies.

Advertisement