Jump to content
  • Advertisement
Sign in to follow this  
Adams555

Render text above an object.

This topic is 5018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I want to render text above an object, or at least near the object. I have a mesh, it's xyz coordinates, and the camera's xyz coordiantes, and probably anything else that would be needed. I have no idea how to do this. Any help would be appreciated. Thanks. Also, I'm using d3dfont, so I need screen coordiantes. (BackBuffer is 800x600) Adam

Share this post


Link to post
Share on other sites
Advertisement
Calculate a line from the object's position to the camera's position. Set a plane (a logical/invisible one perpendicular to the camera's view vector) at x const distance of the camera say 1.0f, calculate where that line cuts the plane and place your text somewhere arrownd that point, render the text always at plane's distance of the camera if you want it to be always readable, no matter how far the object is.

Another possibility is to render your text into a texture and draw a quad right above your object using that texture, like a billboard.

Share this post


Link to post
Share on other sites
Note that the first parameter to draw text is a sprite. If you call DrawText inside of the sprite's Begin/End block it's beahvior will reflect that of the sprite and whatever flags you called Begin with. If you use the D3DXSPRITE_OBJECTSPACE flag the text will be drawn using the World/View/Projection transforms set on the device. Use the world matrix to position the text correctly above your object. You will probably have to rotate/scale in the World transform to get the text to look right (not sure what axis it is drawn on). Be careful of the D3DXSPRITE_BILLBOARD it may not behave like you expect and you may want to do the billboarding yourself in the world transform.

I imagine that there are other perhaps faster ways of doing this, but this method has worked for me.

...one more thing, I think that the transforms are applied when you call End or Flush on the sprite and not on every call to DrawText.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!