Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

ID3DXFont can be used to render 2D text, and D3DXCreateText can be used to generate a 3D text mesh you could render as well. In general I would think the 2D approach is preferable, unless you want the text to do something odd like spin in 3D space.

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.

share|improve this answer
    
Good answer. One last bit: turn off Z testing before you render the text so that it doesn't render behind stuff. –  munificent Jan 27 '11 at 23:30
    
Ah yea, good point. And thanks :D –  Josh Petrie Jan 28 '11 at 1:34
    
Word of warning: D3DXCreateText creates meshes that are the same height regardless of the size of the font selected into the DC (CreateFont). –  Pierre Nov 28 '12 at 17:23
add comment

You can use D3DXCreateText to create a text "mesh", which you can then render however you like.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.