Jump to content
  • Advertisement
Sign in to follow this  
roloenusa

Displaying text with DirectX

This topic is 3806 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 everyone, I'm currently trying to display some text on the screen. I've done some reading and research but I can't seem to find a definitve answer on what's a better, faster or/and more efficient method. I'm pretty new to directx so even a good tutorial on this can be extremely useful. What I've read so far is that creating a sheet of characters and painting them on the screen is much easier and faster than using D3DFONT, but those post seem to be from 2003 and ealier. Have things changed? is it still easier or is it better to use the libraries in DirectX? Thank you soo much for your time! =D

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I would like also have an answer about this.

On my project, I'm using sprites to display text (I use common code with opengl, so it's better to have a same display).

I'm just using DXFONT (with "nice" arial) for a debug console, and clearly, when this console is activated, the framerate is divided by two...
But I think - and I hope - it's due to a wrong coding (I should take an hour to check... But if someone confirms there is no major impact on fps...)

Share this post


Link to post
Share on other sites
It depends on your requirements as to what to use for in-game fonts. ID3DXFont is a great general purpose solution. If you just want some debug text to display information such as framerate then ID3DXFont is just fine. However since it is a general purpose solution, if you want a full-scale, feature rich font system, you will have to roll your own.

For the two of you however, i strongly recommend that you use ID3DXFont until you KNOW that you need something better. It can be a lot of work to write a font system (depending on how you want to render it mainly).

I'll address your "framerate in half" comment. The fact that your framerate is chopped in half is not a good indicator. What you should be worried about is the time taken to draw a frame, which is 1 divided by the FPS. An example:

- 1000fps is 0.001 seconds per frame, dividing it by 2 gives you 0.002 seconds per frame. This is not a serious increase in time taken.

- 10fps is 0.1 seconds per frame, dividing it by 2 gives you 0.2 seconds per frame. This is a much large slow down.

It is a common mistake to misinterpret how the FPS changes.

Hope that helps,

Share this post


Link to post
Share on other sites
The fastest way is to have each character drawn on a texture and a quad for each character and a vertex buffer to render them.

AFAIK Sprites are slow and the built in text methods are slow. But it's always confused my why sprites are slow because you would think a sprite would be nothing more than a quad.

Also in most cases you would use a transformed vertex format so no matter your camera the text will always appear in 2d at the front of screen. But in cases where you want in-game text to appear in the 3d world you may opt to go for an untransformed vertex format.

Other notes:

- If you want create your own font textures use GDI and not GDI+ to measure the characters because GDI is much more accurate. On the other hand use GDI+ to render them so as to maintain the alpha channel and anti-aliasing
- A program like the Bitmap Font Generator helps if you want to embed fonts and also does the measusing of text for you

Share this post


Link to post
Share on other sites
I have several apps using D3DXFONT and even drawing lots of text (tried with and without a text sprite for the font) each frame along with >30000 polys, I have no trouble maintaining 60 fps.

I second Dave's advice that you just use D3DXFONT until you need something better (if ever). Even when you think you need something better, you probably don't.

Share this post


Link to post
Share on other sites
Quote:
Original post by Headkaze
AFAIK Sprites are slow and the built in text methods are slow. But it's always confused my why sprites are slow because you would think a sprite would be nothing more than a quad.


Sprites aren't slow at all...in fact they should be extremely fast as long as you're batching your quads. The reason ID3DXFont is so slow is because it uses GDI to render text to the surface of a texture (which is then drawn to the screen using ID3DXSprite), which requires expensive synchronization between D3D and GDI as well as between the CPU and GPU.

Share this post


Link to post
Share on other sites
Random old link. I actually looked into what ID3DXFont does internally a while ago and found it does some rather odd stuff. That's all 2 years old now, it's entirely possible ID3DXFont has been optimised more since then.

I have my own text rendering system that essentially re-invents ID3DXFont. The only reasons for that is so I can use my own sprite system to render the glyphs, and to use my engine's texture atlas code.

Share this post


Link to post
Share on other sites
why not just use TextOut(), which is a win32() command, after all your rendering.

I dont know if its much faster than the idxfont, but i assume idxfont is a wrapper for it.

Share this post


Link to post
Share on other sites
Quote:
Original post by wforl
why not just use TextOut(), which is a win32() command, after all your rendering.

I dont know if its much faster than the idxfont, but i assume idxfont is a wrapper for it.
TextOut will be much slower since using it would involve copying the backbuffer to system memory (Losing all parallelism, and causing a huge stall), updating it, then copying it back to VRAM to present.

ID3DXFont will write characters to a texture only once, and then use that texture from then on. It'll only involve copying anything from system memory to VRAM (Since it uses a managed texture which has a system memory backed copy), it won't be nearly as frequent (Not every frame, certainly), and it shouldn't cause a stall.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!