简体   繁体   English

如何使用DirectX 9渲染2D叠加层

[英]How to use render a 2D overlay with DirectX 9

So I have a game I'm working on in C++ with DirectX 9. It's 3D, but I want to have a 2D overlay. 因此,我有一个正在使用DirectX 9在C ++中进行开发的游戏。它是3D的,但是我想要一个2D的叠加层。 I've heard that I could use D3DXMatrixOrthoLH, but I'm very confused on how to use it. 我听说我可以使用D3DXMatrixOrthoLH,但是我对如何使用它感到非常困惑。 I'm more familiar with OpenGL, where I could simply switch between 3D and 2D by initiating the view. 我对OpenGL更熟悉,可以在其中通过启动视图在3D和2D之间切换。 An example of how to do this with DirectX 9 would be great! 一个使用DirectX 9做到这一点的例子将是很棒的!

Thanks very much! 非常感谢!

You can use the ID3DXSprite class in the D3DX9 library to draw 2D textures for a HUD. 您可以使用D3DX9库中的ID3DXSprite类为HUD绘制2D纹理。

You can use identity transforms and draw using normalized coordinates (-1,-1 to 1,1) with depth testing off, but most people find it less intuitive to position elements. 您可以使用身份变换并使用深度测试未完成的归一化坐标(-1,-1至1,1,1)进行绘制,但是大多数人发现放置元素不太直观。 Instead, they create a simple orthographic projection transform that maps the normalized coordinates to something more natural like pixels (0,0 to width,height). 取而代之的是,他们创建了一个简单的正交投影变换,将归一化的坐标映射到更自然的东西,例如像素(从0,0到width,height)。 You can use D3DXMatrixOrthoOffCenterLH if you are using left-handed view coordinates or D3DXMatrixOrthoOffCenterRH if you are using right-handed view coordinates (which doesn't matter for 2D drawing but it is less confusing to make it consistent with your 3D drawing). 您可以使用D3DXMatrixOrthoOffCenterLH如果您使用左手视图坐标或D3DXMatrixOrthoOffCenterRH如果您正在使用右手视图坐标(不用于2D绘图重要,但它是减少混乱,使之与你的3D绘图一致)。

Why are you using legacy DirectX 9 which is over a decade old? 为什么要使用已经使用了十年的传统DirectX 9? If you were using Direct3D 11 instead, you can make use of DirectX Tool Kit and the SpriteBatch class to draw your HUD. 如果使用的是Direct3D 11,则可以使用DirectX工具包SpriteBatch类绘制HUD。 The DirectX SDK is deprecated, the D3DX library is deprecated, D3DXMath is deprecated, and debugging for DirectX 9 is not supported on Windows 8 or later. 不推荐使用DirectX SDK,不推荐使用D3DX库,不推荐使用D3DXMath,并且Windows 8或更高版本不支持DirectX 9的调试。 See MSDN 参见MSDN

Thanks for all the help guys. 感谢所有帮助人员。 I've decided to scratch DirectX and go back to good old OpenGL, which I'm much more familiar with. 我决定从头开始Dir​​ectX,然后回到我更熟悉的旧OpenGL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM