LPD3DXSPRITE pSprite parameter in draw method of ID3DXFont

Started by
5 comments, last by nhatkthanh 19 years, 10 months ago
can someone explain to me what this parameter does? An example would help a lot. thanks.
Advertisement
Font works through Sprite now. By creating a sprite object and using it in the Font API, you can get a perf boost (if you''re making more than one call to DrawText()). The reason being that nothing is actually drawn until ID3DXSprite::End() or ID3DXSprite::Flush(), and all the draw operations are sorted by texture.

To use it, just create an ID3DXSprite() object (D3DXCreateSprite() ), and when you go to draw, call ID3DXSprite::Begin(D3DXSPRITE_APLHABLEND | D3DXSPRITE_BILLBOARD | D3DXSPRITE_SORT_TEXTURE), pass that pointer to each DrawText call, and call ID3DXSprite::End().

My spoon is too big.
[sub]My spoon is too big.[/sub]
ID3DXFont uses an internal sprite (a static one) and calls the Sprite''s Begin() and End() methods for EVERY line of text you call - unless you pass it a sprite pointer that is already between draw calls anyway.

I''ve set mine up like this:

quote:
//----------------------------------
// CResourceManager::DrawText()
// Draws text to the screen using
// the current font.
//----------------------------------
void CResourceManager::DrawText(String sText,DWORD dwColor,UINT uiTop, UINT uiLeft,UINT uiHeight, UINT uiWidth, bool bWrap)
{
assert(m_pFontSprite);

RECT rc;
SetRect( &rc, uiLeft, uiTop, uiWidth, uiHeight);

DWORD dwFlags;
if(bWrap)
dwFlags = DT_WORDBREAK | DT_NOCLIP;
else
dwFlags = DT_NOCLIP;

m_pFonts[m_ridCurrentFont].Font->DrawText(m_pFontSprite,sText, -1, &rc,dwFlags, dwColor);
}

//----------------------------------
// CResourceManager::BeginTextBlock()
// Starts a block of text.
//----------------------------------
void CResourceManager::BeginTextBlock()
{
// Make sure we have a sprite first.
if(!m_pFontSprite)
{
HRESULT hr = D3DXCreateSprite(GraphicsEngine.GetDevice(),&m_pFontSprite);
if(FAILED(hr))
{
D3DERROR(hr);
}
}
m_pFontSprite->Begin(D3DXSPRITE_SORT_TEXTURE);
}

//----------------------------------
// CResourceManager::EndTextBlock()
// Ends a block of text.
//----------------------------------
void CResourceManager::EndTextBlock()
{
m_pFontSprite->End();
}


In my interface drawing method, I do the following:

1.) Call BeginTextBlock()
2.) Call DrawText() for all of my fonts.
3.) Call EndTextBlock()

It makes a HUGE difference in performance.

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

in the documentation:

pSprite
[in] Pointer to a ID3DXSprite object that contains the string. Can be NULL, in which case Microsoft® Direct3D® will render the string with its own sprite object.

"contains the string" I''m not sure what that meant. So this is what I did, I call D3DXCreateSprite, then call sprite->begin and then pass that sprite object to all my drawtext methods then finally call sprite->end(). Is this correct? because I got no text drawn.
If you use the sprite with ID3DXFont you must specify alpha in the sprite->Begin() call.
yep I have the D3DXSPRITE_ALPHABLEND flag in the sprite->begin() but no result.

it works now thanks, I got some extra flag in there.

[edited by - nhatkthanh on June 11, 2004 1:54:23 PM]
A common mistake people make with ID3DXFont::DrawText is to pass 0x00ffffff (transparent white) in as the color, and complain they don''t see anything. They really should be passing in 0xffffffff (opaque white) instead.

xyzzy

This topic is closed to new replies.

Advertisement