views:

57

answers:

1

Hello guys,

Let me shortly describe the "battlefield" of my task:

  • Multi-room audio/video chat with more than 1M users;
  • Custom Direct3D renderer;

What I need to implement is TextOverVideo feature. The Text itself goes via network and is to be rendered on the recipient side with Direct3D renderer. AFAIK, it is commonly used in game development to create your own texture with letters/numbers and draw this items. As far as our application must support many languages we ought to use smth standard. That's why I've being working with ID3DXFont interface but I've found out some unsatisfied limitations.

What I've faced is lack of scalability. E.g. if user is resizing video window I have to RE-create D3DXFont with new D3DXFONT_DESC while he's doing that. I think it is unacceptable. That is why the ONLY solution I see (due to my skills) is somehow render the text to a texture and therefore draw sprite with scaling, translation etc.

So, I'm not sure if I go into the correct direction. Please help with advice, experience, literature, sources.. Thanks a Lot!

+1  A: 

Your question is a bit unclear. As I understand it, you want easily scalable font.

I think it is unacceptable

As far as I know, this is standard behavior for fonts - even for system fonts. They aren't supposed to be easily scalable.

Possible solutions:

  1. Use ID3DXRenderTarget for rendering text onto texture. Font will be filtered when you scale it up too much. Some people will think that it looks ugly.
  2. Write custom library that supports vector fonts. I.e. - it should be able to extract font outline from font, and build text from it. It will be MUCH slower than ID3DXFont (which is already slower than traditional "texture" fonts). Text will be easily scalable. Using this way, you are very likely to get visible artifacts ("noise") for small text. I wouldn't use that approach unless you want huge letters (40+ pixels). Freetype library may have functions for processing font outlines.
  3. Or you could try using D3DXCreateText. This will create 3D text for ONE string. Won't be fast at all.

I'd forget about it. As long as user is happy about overall performance, improving font rendering routines (so their behavior looks nice to you) is not worth the effort.

--EDIT--

About ID3DXRenderTarget.
EVen if you use ID3DXRenderTarget, you'll need ID3DXFont. I.e. you use ID3DXFont to render text onto texture, and then use texture to blit text onto screen.
Because you said that performance is critical, you can delay creation of new ID3DXFont until user stops resizing video. I.e. When user starts resizing video, you use old font, but upscale it using texture. There will be filtering, of course. Once user stops resizing, you create new font when you have time. you probably can do that in separate thread, but I'm not sure about it. OR you could simply always render text in the same resolution as video. This way you won't have to worry about resizing it (it still will be filtered - along with the video). Some video players work this way.
Few more things about ID3DXFont. There is one problem with ID3DXFont - it is slow in situations where you need a lot of text (but you still need it, because it supports unicode, and writing texturefont with unicode support is pain). Last time I worked with it I optimized things by caching commonly used strings in the textures. I.e. any string that was drawn more than 3 frames in the row were rendered onto D3DFMT_A8R8G8B8 texture/render target, and then I've been copying that string from texture instead of using ID3DXFont. Strings that weren't rendered for a while, were removed from texture. That gave some serious boost. This solution, however is tricky - monitoring empty space in the texture, removing unused strings, and defragmenting the texture isn't exactly trivial (there is nothing exceptionally complicated, but it is easy to make a mistake). You won't need such complicated system unless your screen is literally covered by text.

SigTerm
Thank you very much for your reply!"Unacceptable" - I meant that creating D3DXFont takes to much resources and performance is crucial for our software. But if I understood you correctly possible solutions number 2 and 3 are even worse.ID3DXRenderTarget-yes,I thought of smth like that. But I couldnt find enough examples of how to use it. What I was afraid of - is that somebody would tell me "Hey, DO NOT use D3DXFont! Its performance is the worst! ID3DXRenderTarget IS the solution!" So tell me please, should I move on with D3DXFont approach or go deeper into ID3DXRenderTarget technique?
Dalamber
@Anton: I've updated my answer.
SigTerm
Thanks again! I would appreciate if you can give me an example of how to render ID3DXFont to a texture.. *SCRATCH* Too few information about ID3DXRenderTarget. Thanks in advance!Btw, I tried recreating font dynamically during resize and yes - the CPU usage while resizing is comparatively high..
Dalamber