使用DX11渲染文本 [英] Rendering text with DX11

查看:98
本文介绍了使用DX11渲染文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在SlimDX中在屏幕上绘制文本.

I am trying to figure out how to draw text on screen in SlimDX.

最初的研究并不令人鼓舞.我发现的唯一具体示例是:

Initial research is not encouraging. The only concrete example I found was this:

http://www.aaronblog.us/?p=36

我正在尝试将此代码移植到我的代码中,但是事实证明这非常困难,而且我开始怀疑4小时后是否是正确的方法.

I am trying to port this to my code, but it's proving extremely difficult, and I'm beginning to wonder after 4 hours if this is the right way to go.

本质上,似乎很难做一些像在屏幕上书写文本一样简单的事情.亚伦的方法似乎是目前唯一可行的方法.没有其他比较点.

Essentially it seems quite difficult to do something as simple as writing text to the screen. Aaron's method seems the only one out there which is practical at the moment. There are no other points of comparison.

其他人有没有可以提供的建议?

Does anyone else have any advice they could offer?

P.S.我怀疑我现在可以为字母创建单个图像,并编码一个例程以将字符串转换为一系列精灵.不过,这样做似乎有点疯狂.

P.S. I suspect I could have created individual images for letters by now, and coded a routine to convert a string into a series of sprites. It does seem slightly insane to do this though.

推荐答案

渲染文本确实有点复杂.呈现常规文本的唯一方法是使用Direct2D/DirectWrite.而且只有DirectX10支持此功能.因此,您必须创建DirectX 10设备,DirectWrite和Direct2D工厂.然后,您可以创建一个可由DirectX 10和11设备使用的共享纹理.

Rendering text is a bit complex, indeed. The only way to render general text is to use Direct2D / DirectWrite. And this is only supported in DirectX10. So you have to create a DirectX 10 device, DirectWrite and Direct2D Factories. You then can create a shared texture that can be used by both DirectX 10 and 11 devices.

此纹理将在渲染后包含文本.亚伦使用此纹理将其与全屏融合.因此,您可以使用DirectWrite绘制完整的字符串.本质上,这就像绘制带纹理的四边形.

This texture will contain the text after rendering. Aaron uses this texture to blend it with the full screen. Therefore, you can use DirectWrite to draw complete strings. Essentially, this is just like drawing a textured quad.

执行此操作的另一种方法是,如您已经提到的,绘制一个Sprite表并将字符串拆分为几个Sprite.我认为,后者的方法要快一些,但我尚未对其进行测试.我在 Sprite&文字引擎.请参见方法 AssertDevice CreateCharTable

Another way of doing this is, as you already mentioned, drawing a sprite sheet and splitting strings into several sprites. I assume, the latter way is a bit faster, but I haven't tested it yet. I used this method in my Sprite & Text engine. See methods AssertDevice and CreateCharTable

这篇关于使用DX11渲染文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆