DX 9 (2003 summer update) - ID3DXFont

Started by
9 comments, last by Night Elf 19 years, 10 months ago
Is anyone using the new ID3DXFont interface? I''m moving my engine to DX 9 and I found a lot of new functions and some missing ones. I don''t understand the new functions completely and I don''s seem to find any tutorials on the Internet that use this new version of the ID3DXFont. (And, as usual, the SDK documentation is useless.) Can anyone explain the following functions?
GetGlyphData()
PreloadCharacters()
PreloadGlyphs()
PreloadText()
I can understand neither what the functions are supposed to do nor their parametters. And what''s all that about glyphs...? I would really appreciate your help. Mariano Ruggiero Lead Programmer ONIRIC GAMES
Advertisement
Glyphs are the individual figures which get displayed on screen. They are different from characters, since in some languages, multiple characters may combine to form a single glyph, etc.. See GDI documentation on Glyphs for more information.

ID3DXSprite::GetGlyphData lets you get the texture and rectangle for a given glyph in ID3DXFont''s glyph cache. Dunno why you''ll really need to use it.. but if you want it, its there.

PreloadText, PreloadCharacters, and PreloadGlyphs all basically do the same thing, just with different kinds of inputs. These functions force ID3DXFont to load glyphs into its cache. If you don''t preload, then the glyphs are loaded lazily when they are first seen.

xyzzy
How should I use PreloadCharacters(UINT First, UINT Last), for example? I don''t understand the parameters. Are they ASCII codes?

Could someone explain the parameters of the

GetGlyphData(  UINT Glyph,  LPDIRECT3DTEXTURE9 *ppTexture,  RECT *pBlackBox,  POINT *pCellInc)


function?

It seems like I could use that function to provide my own texture and make a custom bitmap font. Is that so?
You could use PreloadCharacters like this:

pFont->PreloadCharacters(''a'', ''z'');
pFont->PreloadCharacters(''A'', ''Z'');
pFont->PreloadCharacters(''0'', ''9'');

GetGlyphData RETURNS you a pointer to the texture ID3DXFont is using to cache the glyph. It does not let you pass one of your own in, or modify the data.

pBlackBox returns the sub-rect of the texture which contains the glyph. (The texture can contain many glyphs.)

pCellInc returns the distance from the origin of the current character to the origin of the next character.

xyzzy
While we''re on the subject of the summer update to ID3DXFont, do people generally agree that it''s faster to use it now? Or is it still faster to write your own class to draw fonts in Direct3D 9?

I ask because before last summer, I wrote my own class to dynamically create a bitmap of font characters and render them in Direct3D (either using 2D or 3D quads--the same class handles both). It runs pretty fast, and doesn''t bog down the frame rate like ID3DXFont used to. However, I realize that I''ve only got a few years programming in C++ professionally, so my own D3D Font class is probably not as fast as it could be.

How much faster are the new ID3DXFont functions?
I am always open to feedback, positive or negative...
Significantly. Especially if you''re doing multiple draw calls with the same font. You can run through one sprite which will sort things by texture (glyph images) and minimize state changes. It''s especially good for variable-spaced fonts.

It''s easy to use too. Give it a shot and compare timings. I bet you''ll find it''s about as fast as a good by-hand solution.

My spoon is too big.
[sub]My spoon is too big.[/sub]
quote:Original post by xyzzy00
GetGlyphData RETURNS you a pointer to the texture ID3DXFont is using to cache the glyph. It does not let you pass one of your own in, or modify the data.

pBlackBox returns the sub-rect of the texture which contains the glyph. (The texture can contain many glyphs.)

pCellInc returns the distance from the origin of the current character to the origin of the next character.


So, would I use it something like this?

LPDIRECT3DTEXTURE9 pTex;RECT               Rect;POINT              CellInc;pFont->GetGlyphData(''A'', &pTexture, &BlackBox, &CellInc);


Is the first parameter OK?

I still can''t get the CellInc parameter... Could you explain it a bit better?

So, anyway, what could someone use this function for? Why would someone what this info?

Mariano Ruggiero
Lead Programmer
ONIRIC GAMES
ID3DXFont / ID3DXSprite are probably faster than 99% of programmers could come up with. Drawing 500 lines of text with this interface (and doing nothing else at all) yields a frame rate of about 900fps in debug mode on my GeforceFX 5900 / Athlon XP 2000+.

You could POSSIBLY do something faster, but you probably won''t - and unless portability is a concern, you''re wasting your time.

Actually, if portability is a concern, you should still use D3DXFont for a D3D renderer, because your custom code will probably still not work as well.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

You could use it to prepare the font and then hand the glyph information to you for custom rendering.

Put another way, CellInc is a rendering offset used to render glyphs properly.

Very likely you will not need this function at all.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
quote:Original post by Night Elf
Is the first parameter OK?

No.. the first parameter is a glyph index.. not a character.. See GetGlyphIndices.

quote:
So, anyway, what could someone use this function for? Why would someone what this info?

In normal use of ID3DXFont, you will never need to use this function. You could use it if you wanted to look at the actual bits for each glyph. Or if you wanted to draw the glyphs yourself, without using ID3DXFont::Draw.

xyzzy

This topic is closed to new replies.

Advertisement