[英]How to draw line and font without D3DX9 in DirectX 9?
I saw that D3DX9 is not recommended by Microsoft and not shipped with Windows SDK. 我看到Microsoft不推荐D3DX9,Windows SDK也不附带D3DX9。 I would like to adopt.
我想采用。
I'm missing my line drawing utility. 我缺少线条画工具。
How can I replace ID3DXLine and ID3DXFont in "new" DirectX9? 如何在“新” DirectX9中替换ID3DXLine和ID3DXFont?
Generally, lines and fonts are sprites. 通常,线条和字体是精灵。
ID3DXLine
and ID3DXFont
use ID3DXSprite
interface under the hood. ID3DXLine
和ID3DXFont
在ID3DXFont
使用ID3DXSprite
接口。 (Of course, there are other options too, but sprite approach is the most widely used) (当然,还有其他选择,但最常用的是精灵方法)
So, firstly, you will need either 3rd party or your own sprite renderer. 因此,首先,您将需要第三者或您自己的精灵渲染器。 Typically, development of "bedroom" sprite engine, consists of stages:
通常,“卧室”精灵引擎的开发包括以下阶段:
You can choose on what stage you stop. 您可以选择停止的阶段。 Later, you can go back and continue.
稍后,您可以返回并继续。
Then, for straight lines, you will simply draw a thin rectangular sprite. 然后,对于直线,您只需绘制一个细的矩形精灵即可。 User will input values such as beginning, end and thickness of line, and you will need to do some simple math to calculate position and rotation of this sprite.
用户将输入诸如线条的开始,结束和粗细之类的值,并且您将需要做一些简单的数学运算来计算此子画面的位置和旋转。 Sprite can be just colored or have a texture: for dotted lines, stripped lines, lines with pink fluffy kittens etc. Then, you can implement curved lines as a set of straight lines.
Sprite可以仅是彩色的,也可以具有纹理的:对于虚线,带状线,带有粉红色蓬松小猫的线等。然后,您可以将曲线实现为一组直线。 You can optionally add sprites to the ends of line, such as arrows.
您可以选择将精灵添加到行尾,例如箭头。
For text, things can be very complicated (and I will tell only about sprite fonts here): 对于文本,事情可能会非常复杂(我将仅在此介绍精灵字体):
To get characters from font file such as .ttf
to a bitmap (image) you can use library. 要将字符从字体文件(例如
.ttf
转换为位图(图像),可以使用库。 FreeType is a best open-source I know. 我知道FreeType是最好的开源。 Parsing fonts yourself can be... complicated.
您自己解析字体可能会很复杂。
You can then mix all together and draw lines with text texture. 然后,您可以将所有内容混合在一起,并用文本纹理绘制线条。 Or draw text surrounded by frame of lines.
或绘制线条框包围的文本。 Or sprite with a text above it.
或在其上方带有文字的精灵。 Or GUI.
或GUI。 All those stuff will be the sprites.
所有这些东西将是精灵。
If you still using DirectX 9, do you really need to bother with Windows SDK, removing D3DX stuff? 如果您仍在使用DirectX 9,是否真的需要打扰Windows SDK,删除D3DX内容? Maybe you can continue developing with Direct SDK and D3DX if it works for you?
如果适合您,也许您可以继续使用Direct SDK和D3DX进行开发? Note, that if, for some reason, you'll decide to move to DX11, there are DirectXTK , which partially replaces D3DX11 stuff.
请注意,如果由于某种原因决定迁移到DX11,则可以使用DirectXTK ,它可以部分替代D3DX11。 Still, your own, or 3rd party solution will probably be more flexible and suitable for you.
不过,您自己的解决方案或第三方解决方案可能会更灵活并且更适合您。 There are many others applications of sprites in 3D graphics,, such as billboarding, GUI, particles, etc. And as always, reinventing the wheel is a much fun and positive experience ;)
精灵在3D图形中还有许多其他应用,例如广告牌,GUI,粒子等。而且一如既往,重新发明轮子是一种非常有趣和积极的体验;)
Hope it helps. 希望能帮助到你。 Happy coding!
编码愉快!
Why not try and use DirectX 11? 为什么不尝试使用DirectX 11?
Oterhwise OpenGL is supported on almost any platform. 几乎所有平台都支持Oterhwise OpenGL。
I would recommend trying SDL it has helper methods for most 2D stuff you can imagine. 我建议尝试使用SDL,它具有您可以想象的大多数2D东西的辅助方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.