• Announcements

Archived

This topic is now archived and is closed to further replies.

DX 9 (2003 summer update) - ID3DXFont

10 posts in this topic

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()
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
0

Share on other sites
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
0

Share on other sites
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?
0

Share on other sites
You could use PreloadCharacters like this:

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
0

Share on other sites
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?
0

Share on other sites
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.
0

Share on other sites
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
ONIRIC GAMES
0

Share on other sites
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.
0

Share on other sites
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
0

Share on other sites
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
0

Share on other sites
quote:
Original post by DrunkenHyena
Put another way, CellInc is a rendering offset used to render glyphs properly.

Oh, I see - it''s a distance to use when rendering the glyphs, not a distance within the texture. Now I understand.

Thank you very much, you''ve all been very helpful.

Mariano Ruggiero
ONIRIC GAMES
0