Jump to content

  • Log In with Google      Sign In   
  • Create Account


DX 9 (2003 summer update) - ID3DXFont


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Night Elf   Members   -  Reputation: 140

Like
Likes
Like

Posted 09 June 2004 - 07:38 AM

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

Sponsor:

#2 xyzzy00   Members   -  Reputation: 307

Like
Likes
Like

Posted 09 June 2004 - 10:27 AM

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

#3 Night Elf   Members   -  Reputation: 140

Like
Likes
Like

Posted 10 June 2004 - 08:27 AM

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?

#4 xyzzy00   Members   -  Reputation: 307

Like
Likes
Like

Posted 10 June 2004 - 09:09 AM

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

#5 Teric   Members   -  Reputation: 204

Like
Likes
Like

Posted 10 June 2004 - 10:42 AM

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?

#6 RenderTarget   Members   -  Reputation: 398

Like
Likes
Like

Posted 10 June 2004 - 11:05 AM

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.

#7 Night Elf   Members   -  Reputation: 140

Like
Likes
Like

Posted 10 June 2004 - 05:24 PM

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

#8 Etnu   GDNet+   -  Reputation: 880

Like
Likes
Like

Posted 11 June 2004 - 04:30 AM

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.

#9 DrunkenHyena   Members   -  Reputation: 805

Like
Likes
Like

Posted 11 June 2004 - 04:31 AM

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

#10 xyzzy00   Members   -  Reputation: 307

Like
Likes
Like

Posted 11 June 2004 - 06:40 AM

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

#11 Night Elf   Members   -  Reputation: 140

Like
Likes
Like

Posted 11 June 2004 - 03:26 PM

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
Lead Programmer
ONIRIC GAMES




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS