How do you draw text in DirectX 11?

2019-01-22 14:21发布

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?

4条回答
地球回转人心会变
2楼-- · 2019-01-22 14:43

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.

查看更多
时光不老,我们不散
3楼-- · 2019-01-22 14:44

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

查看更多
戒情不戒烟
4楼-- · 2019-01-22 14:59

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.

查看更多
贼婆χ
5楼-- · 2019-01-22 15:07

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

查看更多
登录 后发表回答