# FontFamily for TextBlock in AdvancedDynamicTexture

**URL:** <https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922>\
**Category:** Questions\
**Tags:** gui\
**Created:** [December 25, 2020, 7:56am UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922 "2020-12-25T07:56:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blax/32/37851_2.png) [@Blax](https://forum.babylonjs.com/u/Blax)\
**Post date:** [December 25, 2020, 7:56am UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/1 "2020-12-25T07:56:54Z")

</div>

Hi, Jedi’s )

Please, escape me from trap. I waste 2 awaful days without any results ((

Here is situation

> **[Babylon.js Playground](https://playground.babylonjs.com/#RZU2XN%233)**

We have MeshButton with AdvancedDynamicTexture and TextBlock  
First time (on playground, while font not in cache) - changes font not worked ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/3c68545ef8f744967a4b6d8f4f7e8d52b8320f4a.png)

Second run font properly changed

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/5/564396beb79f021255146b7db94739ac3240fe7f.png)  
I suggest becauce it placed in browser cache and loaded very faster, before some ready statuses for Texure or text block or…??? is setted to true

I was try - checked togheter fonst.ready status, AdvancedDynamicTexture onReady, Internal texture ready, TextBlock dirty. No way.

In my simulator if we make “crutch” as just 500ms timeout and set after this time fontFamily that way:  
(ts.\_texture.getChildren()[0] as Container).children[0].fontFamily = ‘Roboto’; all is ok, but i very need code without ‘crutch’s’ & would like understand how it works.

Please could you help me?!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 25, 2020, 2:28pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/2 "2020-12-25T14:28:41Z")

</div>

The font won’t be loaded until an element is using it. So you should create an element using this font family to force the browser downloading the font right away and not at the first frame:

> **[Babylon.js Playground](https://playground.babylonjs.com/#RZU2XN%2311)**

---

<div class="post-metadata">

**Author:** ![Blax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blax/32/37851_2.png) [@Blax](https://forum.babylonjs.com/u/Blax)\
**Post date:** [December 25, 2020, 4:28pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/3 "2020-12-25T16:28:37Z")

</div>

Yes, exacly, but it is not fairly solition 😉

Situation with lazy font loading and dynamicly changes font for existed elements is normal and can be.  
Additional, BABYLON can do this, as we can see, if switching is after some time.

Question is more complex - how condition we need to check for sure - now we can switch font for TextBlock and font will switch properly, as BABYLON already now can do.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 25, 2020, 6:30pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/4 "2020-12-25T18:30:03Z")

</div>

Well, you know for sure that a font has been loaded by adding a function to `document.fonts.ready.then`, but as explained above you must be sure that the browser has started loading the font by using it in a HTML element. Maybe there’s a possibility to load the font size ourselves by code and instruct the browser of the new font but I don’t know HTML well enough to know.

---

<div class="post-metadata">

**Author:** ![kvasss](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kvasss/32/3774_2.png) [@kvasss](https://forum.babylonjs.com/u/kvasss)\
**Post date:** [December 25, 2020, 7:55pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/5 "2020-12-25T19:55:41Z")

</div>

Hi. I think fontface observer helps you [How to make sure that all fonts are loaded before to start BABYLON.js? - Questions - Babylon.js](https://forum.babylonjs.com/t/how-to-make-sure-that-all-fonts-are-loaded-before-to-start-babylon-js/3127/3)  
[https://www.babylonjs-playground.com/#J3X1EJ#2](https://www.babylonjs-playground.com/#J3X1EJ#2)  
Something like this  
[fontfaceobserver/test at master · bramstein/fontfaceobserver · GitHub](https://github.com/bramstein/fontfaceobserver/tree/master/test)

---

<div class="post-metadata">

**Author:** ![Blax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blax/32/37851_2.png) [@Blax](https://forum.babylonjs.com/u/Blax)\
**Post date:** [December 26, 2020, 11:36am UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/6 "2020-12-26T11:36:33Z")

</div>

Thank you for help!  
In this time we have FontFaceSet WebAPIs and not required any external observers, but i need some other - changed settings after pass some time, not wait all this time for start drawing interface.

Common solution:

1. Load fonts
2. Wait, while fonts is loaded
3. Draw interface

My needs:

1. Draw interface (and give user possible interract with that as soon, as possible)
2. Load font
3. Wait, while fonts is loaded
4. Update interface

Well, we can just rebuild AdvancedDinamycTexture, when new font loading, but i think it not very good way. So, i will continue trying, if found some intresing, will make upd for this topic.

Thanks for answers and direction!

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 26, 2020, 5:12pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/7 "2020-12-26T17:12:50Z")

</div>

Yup would be great to benefit from your experience here and maybe we could then add a standard way in the framework for it 🙂

---

<div class="post-metadata">

**Author:** ![Blax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blax/32/37851_2.png) [@Blax](https://forum.babylonjs.com/u/Blax)\
**Post date:** [January 4, 2021, 11:22am UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/8 "2021-01-04T11:22:00Z")

</div>

In total… all is simpliest )

We can use FontFaceSet API [FontFaceSet - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet)  
for:

- force loading font: document.fonts.load
- checking font state: document.fonts.load or document.fonts.ready promise  
then, we can just update textBlock.fontFamily property or create and apply AdvancedTexture style, when we need.

If we have many fonts and need choisen one - we can use FontFaceSet.check method

All it in doc, and only one small hints:

1. We can use just text-element with font style in html page for browser start font loading. Because before FotnFaceSet.load or page naven’t that block font loading not invoked.  
\<span style="font-family:‘MyFont’\>&nbsp;

> **[Babylon.js Playground](https://playground.babylonjs.com/#RZU2XN%2314)**

Probably it can save some time )

---

<div class="post-metadata">

**Author:** ![Blax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blax/32/37851_2.png) [@Blax](https://forum.babylonjs.com/u/Blax)\
**Post date:** [October 10, 2025, 4:39pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/9 "2025-10-10T16:39:02Z")

</div>

Old topic but i need it again ))

I guess this way is more correct:

somewhere in css:  
@font-face { font-family: ‘FontName’;  
//…(better way copy this from google fonts)  
}

In code  
// before you create any elements:  
`const fontFaceSet = await document.fonts.ready;`  
`await fontFaceSet.load('20px FontName');`

// here we can operate with gui

---

<div class="post-metadata">

**Author:** ![Tarks](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tarks/32/48474_2.png) [@Tarks](https://forum.babylonjs.com/u/Tarks)\
**Post date:** [September 29, 2026, 4:24pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/11 "2026-09-29T16:24:33Z")

</div>

Is there anything to be done on resolving the stroke artifacts? Really need something like this to nail the vibe but the rendering artifacts are making the game look like a highly compressed jpeg

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/5/e5f8fc8c7969e3de3cb3ac6309e511020ae38f37.png)

(Names above the critters heads are Babylon MSDF, the text lower down is HTML rendered)

playCanvas’s implementation seems to work nicely with nice outlines and shadow support, is there anything that could be learned and implemented from that?

> **[PlayCanvas MSDF Font Generator](https://playcanvas.github.io/font-tools/)**

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/b/eb9ac5bdf6b426e8caf362cf5686f9b6f1f98cf4.png)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 29, 2026, 8:46pm UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/12 "2026-09-29T20:46:37Z")

</div>

Hi [@Tarks](https://github.com/Tarks) — I made a [Playground comparison](https://playground.babylonjs.com/#6RLCWP#107) for the stroke artifacts. The left side uses Babylon’s current MSDF shader; the right side uses an experimental shader that calculates edge coverage from the font atlas’s distance range and composites the fill and stroke separately. In my WebGL2 test, the right side looked noticeably cleaner, even when I reduced the text size. Turning off mipmap sampling alone didn’t fix the original.

Could you try the shader override from the Playground **in your own project** , using your font atlas and its `distanceRange`, and let us know whether it improves the names above the critters? The override uses private renderer internals and is GLSL/WebGL2-only, so it’s a diagnostic test rather than a production-ready fix. If artifacts remain, a screenshot at the game’s normal text size and your atlas settings would help narrow down what’s different.

---

<div class="post-metadata">

**Author:** ![Tarks](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tarks/32/48474_2.png) [@Tarks](https://forum.babylonjs.com/u/Tarks)\
**Post date:** [September 30, 2026, 11:22am UTC](https://forum.babylonjs.com/t/fontfamily-for-textblock-in-advanceddynamictexture/16922/13 "2026-09-30T11:22:14Z")

</div>

Hi, firstly really sorry I replied to the the wrong thread, intended to reply to [MSDF Text renderer - #106 by Deltakosh](https://forum.babylonjs.com/t/msdf-text-renderer/58406/106?page=6)

Thanks for your playground, I played with it and I think is most cases it does look a bit better on the right, there are some edge cases where it has a few more artefacts, I uploaded the font I’m using for a better comparison of my use case, here’s an tweaked playground [https://playground.babylonjs.com/#6RLCWP#109](https://playground.babylonjs.com/#6RLCWP#109)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/9/e9c07c02e420ec9e0c95c36c213bee0a97a1921a.png)

I noticed the one on the right is more susceptible to the letters ‘black-boxing’ when at distance

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/6/666a8680f1b0bbb8efca0fd9a11d5cfe8c82aac5.png)

Font setup I’m using  
[https://www.dropbox.com/scl/fi/44jhespvq1t2ytepuv7fz/RussoOne-Regular.json?rlkey=vj908518k5brh4h1i1kv8mage&st=04njcny0&dl=1](https://www.dropbox.com/scl/fi/44jhespvq1t2ytepuv7fz/RussoOne-Regular.json?rlkey=vj908518k5brh4h1i1kv8mage&st=04njcny0&dl=1)

[![](https://dl.dropboxusercontent.com/scl/fi/uivr10o1u5r5ryiyr0gof/RussoOne-Regular.png?rlkey=djtqvkjl2e289hpziax69j2ae&st=ne9knxxg&dl=1&raw=1) ](https://dl.dropboxusercontent.com/scl/fi/uivr10o1u5r5ryiyr0gof/RussoOne-Regular.png?rlkey=djtqvkjl2e289hpziax69j2ae&st=ne9knxxg&dl=1&raw=1)

As a test I asked Claude to see if it could take the PlayCanvas shader and use it in my project which seems to work reasonably well & has shadow support so I don’t need to double render the text for that.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/2/62b22adbec2f6af8300f2a1b4f4a6e2c2652f4ff.png)

That’s not a viable option for any number of reasons but uploading in case it’s useful [https://www.dropbox.com/scl/fi/trtpy43psj8w4haqa0n3p/pctr.ts?rlkey=9n90m8eolsvan6mw2mfxmvz7x&st=3krhy7dr&dl=1](https://www.dropbox.com/scl/fi/trtpy43psj8w4haqa0n3p/pctr.ts?rlkey=9n90m8eolsvan6mw2mfxmvz7x&st=3krhy7dr&dl=1)
