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.
From the looks of it you can use the GetGlyphData() function of the ID3DXFont interface. Pass in the address of a RECT and the glyph identifier (should be just the character casted ti a UINT), and the RECT should get filled with the minimum character area. Alternatively, if that dosnt work, you can get the HDC of the font and then use the GetTextExtentPoint32() WIN32 function.
HDC dc = mpDXFont->GetDC();
char charater = 'A';
GetTextExtentPoint32( dc, (char*)&character, 1, &size );
// size.cx // width
// size.cy // height
The Glyph function should be more reliable though (if it indeed does what it looks like it should be doing) because that's part of the interface.
Has there been an update on DX9 which changes the functionality of the ID3DXFont interface? MSDN only lists a very limited interface (mainly just begin, end and draw), and these are the only functions I can access?
Yes there has been an update.
Link to latest ID3DXFont interface
This is from the summer update SDK. It wasnt in the original dx9 SDK.
Thanks for that Bladder. I really should keep track of what Microsoft release. Im getting the latest update now