• Advertisement

Archived

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

LPD3DXSPRITE pSprite parameter in draw method of ID3DXFont

This topic is 4973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
If you use the sprite with ID3DXFont you must specify alpha in the sprite->Begin() call.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement