Using fonts with Direct3D 8 - speed problems, please help
by Kevin Wood · in Technical Issues · 06/28/2002 (10:26 am) · 4 replies
I am using D3DXCreateFontIndirect() to create a font and then m_ID3DXFont.Begin(), ID3DXFont.DrawText(), and m_ID3DXFont.End()to draw text onto the screen in a game I am developing. I would think that this would be the way to do things since it is the DirectX method, but when I draw a simple line of text this way it drops my FPS from about 60 to about 45, and 2 lines (and 2 calls to ID3DXFont.DrawText()) would drop it to about 30-35. When I call ID3DXFont.DrawText() once with multiple lines (what I mean is that my string had newlines (\n)), however, it only drops my FPS as if it were one line, so therefore calling ID3DXFont.DrawText() must take a lot of time. Is there a solution to my problem or a different method of drawing text? Please do not tell me to use OpenGL, I am happy with Direct3D.
Thanks for taking the time to read my message, I know it was a long, semi-technical one, and not worded very well, lol.
Thanks for taking the time to read my message, I know it was a long, semi-technical one, and not worded very well, lol.
#2
I have a full 2D layer in my game that uses that method (to surfaces rather than textures as all my 2D compositing is done in system mem and then uses a dirty rect scheme to update a set of ortho textured quads as needed to avoid sucking up all of vram with the extensive GUI elements).
My code was inspired by Microsoft's "3D Text" sample in the DX SDK, look particularly at the CD3DFont class. This method isn't quite as feature rich, and requires creating a cached instance of each font/size/style combination that will be used, but it is orders of magnitude faster because the D3DX font code actually makes a lot of calls to GDI under the hood every time you print text which can substantially stall your graphics pipeline.
06/28/2002 (3:59 pm)
I'd say try to stay away from the higher level D3DX font handling. It is noticably slower than using the second method fred described. I have a full 2D layer in my game that uses that method (to surfaces rather than textures as all my 2D compositing is done in system mem and then uses a dirty rect scheme to update a set of ortho textured quads as needed to avoid sucking up all of vram with the extensive GUI elements).
My code was inspired by Microsoft's "3D Text" sample in the DX SDK, look particularly at the CD3DFont class. This method isn't quite as feature rich, and requires creating a cached instance of each font/size/style combination that will be used, but it is orders of magnitude faster because the D3DX font code actually makes a lot of calls to GDI under the hood every time you print text which can substantially stall your graphics pipeline.
#3
06/28/2002 (5:03 pm)
Thanks guys. I don't know why I wasn't doing this earlier, but I'll put all of the font characters into a texture and blit them on the screen (not even billboarding... the 2D-in-3D sprite method... sorry I don't know what it's called, lol).
#4
06/28/2002 (7:42 pm)
manipulate the frame buffer directly could be slow
fred
Alternatively, you can do as eveyone else is doing, drawing all the characters in a texture, then map the specific part of this texture on a TLVertex quad to show one character.