如何在 DirectX 11 中绘制文本?
在 DirectX 10 中,您可以使用 D3DX10 提供的字体接口。在 DirectX 11 中,您应该使用 DirectWrite。但看起来 DirectWrite 本身并不与 Direct3D 对话?我缺少一些基本的东西吗?如何使用 DirectX 11 绘制简单文本?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
DirectXTK 库中有一个
SpriteFont
类,可以将文本渲染到 DirectX11设备上下文。There's a
SpriteFont
class in the DirectXTK library that can render text to a DirectX11 device context.2014 年编辑:
正如评论中所指出的,RasterTek 教程的链接不再起作用,这里是 RasterTek 的 Webarchive 由 RadioSpace 提供。
原始答案的第二点也不再有效,因为现在可以与 Direct2D 共享 D3D11 后缓冲区,并通过它使用 DirectWrite 绘制文本。
2017 年编辑:
RasterTek 仍在运行:D3D11 中的字体渲染
我知道两个选项有关直接写入的第二个选项需要在 d3d11 之间共享后备缓冲区和 d3d10.1 设备,并使用 dwrite + d2d + d3d10.1 渲染 gui,使用 d3d11 设备渲染 3d 几何图形并将其全部合并到后台缓冲区 查看 DieterVW 在该线程上的帖子
此时 dwrite 和 d2d 不接受使用 d3d11 设备创建的表面进行渲染。但希望微软能尽快做到这一点。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 optionsmake 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.我最近将 DirectX 10 应用程序转换为 DirectX 11,并在搜索相同答案时看到了这篇文章。 Zeela提到的Rastertek教程很好,但我继续搜索并找到了FW1FontWrapper。仅仅大约 30 分钟后,我就完成了将其集成到我的项目中,并且看起来效果很好。下载部分提供 x86 和 x64 软件包,包括标头、库和 DLL。我只是在做一个简单的文本输出,所以我不能对 API 说太多,除了我所做的(每秒输出帧数),只花了大约 5 行代码(包括创建/释放包装对象)。根据他的样本,它似乎提供了比我目前使用的更多的选项。
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.
使用 DirectWrite ,它支持高质量文本渲染、与分辨率无关的轮廓字体以及完整的 Unicode 文本和布局支持。
Use DirectWrite , it support high-quality text rendering, resolution-independent outline fonts, and full Unicode text and layout support.