Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SpreeTree

LPD3DXFONT and string width

This topic is 5301 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

Im using the LPD3DXFONT structure to create simple 2D fonts, but i am having problems layng out the text because I can''t find a way of pre-calculating the final width and height of the printed text. I know that LPD3DXFONT::DrawText returns the height of the string, but I cant find anyway of getting the width of the text. Any ideas? Cheers Spree

Share this post


Link to post
Share on other sites
Advertisement
As of Direct3D 8, you could pass a flag to DrawText() so that it filled the rect you passed it with the proper values, then you had to call it again with that rect to actually do the drawing. IIRC, I took out the "filling rectangle" call, and it seemed to work fine, but then I realized how agonizingly slow it was.

There are two Win32 functions that can return the width of a string, I can''t remember what they are offhand but one is something like GetABCWidths() or something.. *looks in psdk* they''re GetCharWidth32() and GetCharABCWidths(), but it seems that they''re only for single characters. Worst comes to worst, make a lookup table for your character widths, I guess.

Share this post


Link to post
Share on other sites
You pass in the width and height of each character in the text. You can multiply the width by the number of characters for the final width. Is this what you mean?

Chris

Share this post


Link to post
Share on other sites

  • 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!