How do you draw text in DirectX 11?
Asked Answered
P

4

18

In DirectX 10 you could use the font interface provided by D3DX10. In DirectX 11 you are supposed to use DirectWrite. But it looks like DirectWrite doesn't speak natively to Direct3D? Is there something basic I'm missing? How do you draw simple text with DirectX 11?

Pesade answered 18/4, 2011 at 21:2 Comment(0)
R
9

Edit 2014:

As pointed out in comment, the link to RasterTek tutorials no longer functions, here is a link to Webarchive of RasterTek provided by RadioSpace.

The second point of the original answer is no longer valid either, because its now possible to share D3D11 backbuffer with Direct2D and through it draw text with DirectWrite.

Edit 2017:

RasterTek is still running: font rendering in D3D11


I know about two options

  • make your own font rendering engine see Rastertek DX11 tutorial

  • second option regarding direct write requires sharing backbuffer between d3d11 and d3d10.1 devices and using dwrite + d2d + d3d10.1 to render gui and d3d11 device to render 3d geometry and merge it all in backbuffer see the post from DieterVW on this thread

At this moment dwrite and d2d dont accept surface created with d3d11 device for rendering. But hopefully MS will make it so soon.

Romaic answered 19/4, 2011 at 10:29 Comment(4)
Hey, that Rasertek DX11 tutorial looks great! I'm going to look into that.Pesade
every time I see these old rastertek links I cry. here is a link to the webarchiveArad
@Arad thanks for pointing out that the link no longer worksRomaic
@Romaic thanks for updating your answer I was looking for the D3D11/dxWrite stuff but this had made me put it on the back burner till the weekend maybe not as troublesome as previously thoughtArad
M
10

There's a SpriteFont class in the DirectXTK library that can render text to a DirectX11 device context.

Milkwort answered 3/7, 2013 at 17:42 Comment(1)
The DirectXTK is a dead link.Fagin
R
9

Edit 2014:

As pointed out in comment, the link to RasterTek tutorials no longer functions, here is a link to Webarchive of RasterTek provided by RadioSpace.

The second point of the original answer is no longer valid either, because its now possible to share D3D11 backbuffer with Direct2D and through it draw text with DirectWrite.

Edit 2017:

RasterTek is still running: font rendering in D3D11


I know about two options

  • make your own font rendering engine see Rastertek DX11 tutorial

  • second option regarding direct write requires sharing backbuffer between d3d11 and d3d10.1 devices and using dwrite + d2d + d3d10.1 to render gui and d3d11 device to render 3d geometry and merge it all in backbuffer see the post from DieterVW on this thread

At this moment dwrite and d2d dont accept surface created with d3d11 device for rendering. But hopefully MS will make it so soon.

Romaic answered 19/4, 2011 at 10:29 Comment(4)
Hey, that Rasertek DX11 tutorial looks great! I'm going to look into that.Pesade
every time I see these old rastertek links I cry. here is a link to the webarchiveArad
@Arad thanks for pointing out that the link no longer worksRomaic
@Romaic thanks for updating your answer I was looking for the D3D11/dxWrite stuff but this had made me put it on the back burner till the weekend maybe not as troublesome as previously thoughtArad
H
7

I recently converted a DirectX 10 application over to DirectX 11 and came across this post while searching for the same answer. The Rastertek tutorial mentioned by Zeela is good, but I continued searching and found FW1FontWrapper. After only about 30 minutes, I just finished integrating it into my project and it appears to be working great. The download section provides both x86 and x64 packages including header, library, and DLL. I am just doing a simple text output, so I can't say a lot about the API, except that for what I did (outputting frames per second), it only took about 5 lines of code (including creating/releasing the wrapper object). Based on his samples it seems to provide a lot more options than what I'm using so far.

Hulda answered 24/10, 2011 at 16:51 Comment(1)
link is dead. New github link: github.com/gamelaster/FW1FontWrapperHarrus
O
7

Use DirectWrite , it support high-quality text rendering, resolution-independent outline fonts, and full Unicode text and layout support.

Orinasal answered 25/12, 2013 at 22:30 Comment(1)
DirectWrite is the best way to handle complex text rendering, and particularly international (Asian) fonts. However, keep in mind that DirectWrite requires Direct2D, and Direct2D prior to the DirectX 11.1 Runtime is a bit challenging to use when rendering on Direct3D 11 devices (it natively uses Direct3D 10.1). For Windows Store apps, Windows Phone 8.x, Xbox One, Win32 desktop apps on Windows 8.x, and Win32 desktop apps on Windows 7 SP1 with KB 2670838 you can count count on the easier interop. Otherwise it's using DXGI shared surfaces.Northumbrian

© 2022 - 2024 — McMap. All rights reserved.