# How can I render text above a mesh in DirectX 9?

I want to render some text over a mesh in my DirectX app. It will have a similar application to health bars for units in games, just as text rather than a bar. I'm looking for the simplest way to do this.

It's a Win32 app, I'm using DirectX 9 and I need it to be in 3D (i.e. when the unit is moving around the Z-axis, the text above moves with it).

Any ideas?

• May I ask why you're using DX9? Are you supporting WinXP or something? – 3Dave Oct 27 '16 at 14:44

To find the appropriate place to start rendering the text (for the 2D case), you'll want to use the character's position in world space (perhaps plus some offset vector that provides a position just above the character's head). Then multiply that point by the combined view and projection matrix via something like D3DXVec3Project. This will yield a screen space position you can render the text to. Note that you may need to offset the screen space position by, for example, -(width of text / 2) or use the DT_CENTER flag if you want the text centered.