Sign in to follow this  

ID3DXFont , DirectX 90b

Recommended Posts

Hello again all :) just a quick question : What is the bedst/fastest way to get the Text Width/Height of any given font ? Option 1 : Windows call - GetTextExtentPoint32(ID3DXFont::GetDC, ... Option 2 : When createing font : DC = ID3DXFont::GetDC GetTextExtentPoint32(DC, ... When Releaseing the Font, DeleteDC(DC) Option 3 : Any other way of getting the Width/Height of a text ? Note : For the upcomming release of DX90c, please build this function into the ID3DXFont, would be cool :)

Share this post

Link to post
Share on other sites
You could use the ID3DXFont::DrawText method with the DT_CALCRECT format parameter. That will allow you to calculate the sizes without drawing it. Note if your using C#/MDX, there is a bug in so you can't calculate the size this way but it appears that your using the C++ D3DX Font Stuff.

Share this post

Link to post
Share on other sites
INT DrawText(          LPD3DXSPRITE pSprite,
LPCTSTR pString,
INT Count,
DWORD Format,


[in] Specifies the method of formatting the text. It can be any combination of the following values.
Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.
Determines the width and height of the rectangle. If there are multiple lines of text, ID3DXFont::DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, ID3DXFont::DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, ID3DXFont::DrawText returns the height of the formatted text but does not draw the text.

Centers text horizontally in the rectangle.
Expands tab characters. The default number of characters per tab is eight.
Aligns text to the left.
Draws without clipping. ID3DXFont::DrawText is somewhat faster when DT_NOCLIP is used.
Aligns text to the right.
Displays text in right-to-left reading order for bi-directional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.
Displays text on a single line only. Carriage returns and line feeds do not break the line.
Top-justifies text.
Centers text vertically (single line only).
Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.

Share this post

Link to post
Share on other sites
Original post by Mythar
Dose it matter if I pass NULL (as the Sprite parm) for this, as the text is not drawen (performance) ?

You can try it, since it won't make your computer explode or something.. You aren't afraid of a crashing program, are you? ;P

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this