Large Fonts and CD3DFont and texture limits

Large Fonts and CD3DFont and texture limits

Post by Ron Hile » Tue, 06 Aug 2002 02:11:16



Hey gang,

CD3DFont uses textures to store a bitmap of the font.  It sizes these
textures based on the font height, like so:

// Large fonts need larger textures
     if( m_dwFontHeight > 40 )
         m_dwTexWidth = m_dwTexHeight = 1024;
     else if( m_dwFontHeight > 20 )
         m_dwTexWidth = m_dwTexHeight = 512;
     else
         m_dwTexWidth  = m_dwTexHeight = 256;

That's all fine and well, except some cards (and the Voodoos are the example
that always springs to mind) can't support textures of >256, so this code
won't work on those particular machines.

Becasue my game is designed to work on a large population of machines (some
of which use Voodoo 2's), I can't use this code.  I tried to use only
256x256 textures and scaling the fonts instead, but the larger fonts come
out looking very bad (pixellated).

So, I'm looking for suggestions.  Surely I'm not the only one who has run
into this problem.

I can think of two possibilities, both of which have drawbacks.

1) use system surfaces instead of textures: I *think* these have no size
limits (can anyone confirm?).  This would allow larger fonts to use
appropriately sized surfaces.  The drawback is I'd need to significantly
modify the DrawText routine to use surface locks (and catch and lock the
backbuffer surface as well), and copy data manually to the backbuffer,
instead of using vertex buffers, which isn't a hardware accelerated process,
and I could end up slowing the framerate down badly.

2) I could use multiple 256x256 textures for the larger fonts.  The only bad
thing about this is that I'd have to switch the source texture, possibly
with every letter, and I don't think that'd be good for the frame rate
either!  And it would complicate the DrawText routine as I'd have to
calculate, for each letter, on which texture that letter is sitting.

So, which way is better?  Or is there some other method that y'all could
suggest?  How would / did you handle this issue?

Thanks,

Ron
--
Creation is an act of sheer will
Manifest Destiny -- The Race for World Domination
http://www.veryComputer.com/*ware.com

 
 
 

Large Fonts and CD3DFont and texture limits

Post by Rich [Microsoft Direct3D MV » Tue, 06 Aug 2002 02:18:49


[Please do not mail me a copy of your followup]



Quote:>2) I could use multiple 256x256 textures for the larger fonts.

This is what I'd do.  One thing you might be able to do in order to
reduce texture switching is to group characters by frequency of usage
in the texture, rather than linearly by ASCII code.  You can find
letter frequency tables for a variety of languages.

With the 256x256 texture limit, you're going to be switching textures
often anyway if your scene has significant amounts of detailed
textures.  Its just a fact of life.  You either need to give up some
quality to reduce texture switches, or live with the switching.
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book <http://www.xmission.com/~legalize/book/>
    izfree: Open source tools for Windows Installer
            <http://izfree.sourceforge.net>

 
 
 

Large Fonts and CD3DFont and texture limits

Post by Ron Hile » Tue, 06 Aug 2002 23:14:27




> [Please do not mail me a copy of your followup]



> >2) I could use multiple 256x256 textures for the larger fonts.

> This is what I'd do.

Okay, fair enough.  You're right in that there is a fair amount of source
texture swapping going on, but not after printing every letter! :)

I seem to recall that you must unlock the vertex buffer and DrawPrimitive
before switching source textures, otherwise DX uses the wrong source when
you do get around to doing the DP.  Which means not only am I swapping
textures with every letter, I'm also unlocking the vertex buffer, DPing, and
relocking.  The GDI might be faster :)

But I'll give it a try and see what happens.  If the frame rate hit is
really bad, I may indeed try to group letters by frequency and keep track of
when the source changes to reduce all that nonsense.

Thanks for the suggestion.  I'll let you know how it goes.

Ron
--
Creation is an act of sheer will
Manifest Destiny -- The Race for World Domination
http://www.veryComputer.com/*ware.com

 
 
 

Large Fonts and CD3DFont and texture limits

Post by Rich [Microsoft Direct3D MV » Wed, 07 Aug 2002 00:47:38


[Please do not mail me a copy of your followup]



Quote:>I seem to recall that you must unlock the vertex buffer and DrawPrimitive
>before switching source textures,

You must unlock a vertex buffer before you use it in a DrawPrimitive
command, yes.

Quote:>Which means not only am I swapping
>textures with every letter, I'm also unlocking the vertex buffer, DPing, and
>relocking.

You haven't explained why this is the case -- I've already suggested
ways to avoid switching textures every character.  It depends on how
big your font is -- you can always request a font from Windows that is
larger than any possible texture you could have.  But then it would
also be larger than the screen.  Windows is perfectly happy to let you
do this and if you really need that range of scale then perhaps GDI is
easier, although at extremely large scales it might be better to get
the glyph outlines of the font and treat them as polygons.

What is it you're really trying to do?  Initially you posed it as
purely a large font, small texture problem.
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book <http://www.xmission.com/~legalize/book/>
    izfree: Open source tools for Windows Installer
            <http://izfree.sourceforge.net>

 
 
 

Large Fonts and CD3DFont and texture limits

Post by WTH » Wed, 07 Aug 2002 00:51:55


break your textures into 4 piece components...  4 x 64, up to 4 x 256...

    WTH


> Hey gang,

> CD3DFont uses textures to store a bitmap of the font.  It sizes these
> textures based on the font height, like so:

> // Large fonts need larger textures
>      if( m_dwFontHeight > 40 )
>          m_dwTexWidth = m_dwTexHeight = 1024;
>      else if( m_dwFontHeight > 20 )
>          m_dwTexWidth = m_dwTexHeight = 512;
>      else
>          m_dwTexWidth  = m_dwTexHeight = 256;

> That's all fine and well, except some cards (and the Voodoos are the example
> that always springs to mind) can't support textures of >256, so this code
> won't work on those particular machines.

> Becasue my game is designed to work on a large population of machines (some
> of which use Voodoo 2's), I can't use this code.  I tried to use only
> 256x256 textures and scaling the fonts instead, but the larger fonts come
> out looking very bad (pixellated).

> So, I'm looking for suggestions.  Surely I'm not the only one who has run
> into this problem.

> I can think of two possibilities, both of which have drawbacks.

> 1) use system surfaces instead of textures: I *think* these have no size
> limits (can anyone confirm?).  This would allow larger fonts to use
> appropriately sized surfaces.  The drawback is I'd need to significantly
> modify the DrawText routine to use surface locks (and catch and lock the
> backbuffer surface as well), and copy data manually to the backbuffer,
> instead of using vertex buffers, which isn't a hardware accelerated process,
> and I could end up slowing the framerate down badly.

> 2) I could use multiple 256x256 textures for the larger fonts.  The only bad
> thing about this is that I'd have to switch the source texture, possibly
> with every letter, and I don't think that'd be good for the frame rate
> either!  And it would complicate the DrawText routine as I'd have to
> calculate, for each letter, on which texture that letter is sitting.

> So, which way is better?  Or is there some other method that y'all could
> suggest?  How would / did you handle this issue?

> Thanks,

> Ron
> --
> Creation is an act of sheer will
> Manifest Destiny -- The Race for World Domination
> http://www.veryComputer.com/*ware.com


 
 
 

Large Fonts and CD3DFont and texture limits

Post by Kev » Wed, 07 Aug 2002 03:51:09


I havent looked closely enough but does this class put every possible
display character into the texture? or just 0-9 aA-zZ and punctuation?

another option would be to rewrite parts of the class (or use it as a base
for his own class) so that it only puts the specific characters you need
into a texture.

 
 
 

1. Pixel debris when using Large CD3DFont

Hi,

When using large CD3DFont font size, the text is incorrectly rendered for
some characters, lowercase U with Impact-40 Bold, for example. The faulty
letters are always the same for a given font, font size, font attribute
combination.

I searched the DIRECTXDEV archives and found nothing but ugly hacks like :

Search for the line:
        x += size.cx+1;
and replace it with:
        x += size.cx+10;

or

// Correction 73=I 76=L 105=i 108=l
if(c==73||c==76||c==105||c==108)
   x += 2*size.cx+1;
else
   x += size.cx+1;

Does anyone has a better solution?
--
Laurent TESTUD - http://www.lafaqmfc.com/

2. Straight lines

3. cd3dfont, and uninstalled font

4. Help: Creating 3-D mesh from arbitrary points.

5. Small Fonts/Large Fonts?

6. Calcomp 906 to CGM converter

7. Large fonts and small fonts

8. Large Fonts/Small Fonts ?????

9. Small font to large font problems!!!

10. 800x600 Large Font Vs Small Font

11. From Large fonts to Small fonts?

12. Large fonts/small fonts