简体   繁体   中英

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. I've heard that I could use D3DXMatrixOrthoLH, but I'm very confused on how to use it. I'm more familiar with OpenGL, where I could simply switch between 3D and 2D by initiating the view. An example of how to do this with DirectX 9 would be great!

Thanks very much!

You can use the ID3DXSprite class in the D3DX9 library to draw 2D textures for a HUD.

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. Instead, they create a simple orthographic projection transform that maps the normalized coordinates to something more natural like pixels (0,0 to 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).

Why are you using legacy DirectX 9 which is over a decade old? If you were using Direct3D 11 instead, you can make use of DirectX Tool Kit and the SpriteBatch class to draw your 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. See 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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