Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Using ID3DXSprite in ID3DXFont DrawText()


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
5 replies to this topic

#1 utilae   Members   -  Reputation: 188

Like
0Likes
Like

Posted 07 November 2005 - 06:33 PM

Hi, I am using C++ and Direct3D9. I have been using ID3DXFont DrawText() so far to draw text, but now I want to use ID3DXSprite with ID3DXFont by passing an ID3DXSprite object into the DrawText() function. Can someone give me some example code on how to create an ID3DXSprite object and then passing it into DrawText()?

Sponsor:

#2 MTclip   Members   -  Reputation: 242

Like
0Likes
Like

Posted 08 November 2005 - 02:10 AM

here this should work for you


this is just a function to load a font


// Function for font loading
HRESULT LoadFont(LPD3DXFONT pFont, char* fontName, LPDIRECT3DDEVICE9 pDevice)
{
// clear if not empty <no memory leaks!!>
if(pFont)
pFont->Release()

// font description struct
D3DXFONT_DESC m_fontDesc;

ZeroMemory(&pFont->m_fontDesc, sizeof(D3DXFONT_DESC));
m_fontDesc.Height = 12;
m_fontDesc.Width = 8;
m_fontDesc.Weight = 500;
m_fontDesc.MipLevels = D3DX_DEFAULT;
m_fontDesc.Italic = false;
m_fontDesc.CharSet = 0;
m_fontDesc.OutputPrecision = 0;
m_fontDesc.Quality = 0;
m_fontDesc.PitchAndFamily = 0;
strcpy(m_fontDesc.FaceName, fontName); // name will be something like "Arial"


if(FAILED(D3DXCreateFontIndirect(pDevice,&m_fontDesc,&pFont))
return E_FAIL;

return S_OK;

// Other options
//DT_NOCLIP | DT_WORDBREAK
}





And sample of how to load a sprite and use it to draw text


////// DEMO //////////////////


LPDIRECT3DDEVICE9 m_pD3dDevice // <--- previously defined
//-----------------------------
// Loading <-- only call once
//-------------------------------
LPD3DXFONT m_pFont;
LPD3DXSPRITE m_pSprite;
LoadFont( m_pFont, "Arial", m_pD3dDevice);
if(FAILED(D3DXCreateSprite(m_pD3dDevice, &m_pSprite))
return E_FAIL;

//-----------------
// Render Loop
//----------------------
m_pD3dDevice->BeginScene();
m_pSprite->Begin(); // <--- must be called between LPD3DXSPRITE::Begin()
/// draw the text
pFont->DrawText(m_pSprite, // <-- the sprite
"ALL YOUR BASE ARE BELONG TO ME", // <-- the text
-1, // <-- num characters in string -1 means its null terminated
&rect, // <--- position <limits>
DT_TOP|DT_LEFT, // <--- alignment in the rect
D3DCOLOR_XRGB(0,0,255) ); // Color

m_pSprite->End(); <--- End sprite
m_pD3dDevice->EndScene();





Hope that solves your issues

#3 utilae   Members   -  Reputation: 188

Like
0Likes
Like

Posted 08 November 2005 - 06:42 AM

Thanks heaps.


Ok, my main goal is to draw text in order of z value. So if a texture had z value of 0.0f and another texture had a z value of 1.0f and the text had a z value of 0.5f, then the text would draw in between the two textures.

I know ID3DXSprite can draw sprites in order of z value, but how do you make ID3DXSprite draw text in order of z value?

#4 RenderTarget   Members   -  Reputation: 398

Like
0Likes
Like

Posted 08 November 2005 - 06:55 AM

Exactly the same way. When you call ID3DXSprite::Begin() prior to your font draw calls, pass D3DXSPRITE_SORT_DEPTH_BACKTOFRONT. Sprite will wait until the Flush() or End() call before rendering, and will sort any sprite or font draw calls you made in between.

#5 utilae   Members   -  Reputation: 188

Like
0Likes
Like

Posted 08 November 2005 - 10:44 AM

I have done my interface graphics such as buttons and textboxes using DrawPrimitive(). Do I have to draw them with ID3DXSprite instead in order to have sprites and fonts be sorted properly?


How do I specify where in the z order a piece of text appears when I use DrawText()? For example is there a way to go DrawText(0.5f) (simplified function for this example) to make text draw at 0.5f in z order?


Also, if I use ID3DXSprite to draw my buttons and textboxes, how would I do that (what's the draw function, etc)? And would using ID3DXSprite be slower than DrawPrimitive()?

#6 utilae   Members   -  Reputation: 188

Like
0Likes
Like

Posted 08 November 2005 - 09:46 PM

Anyone able to answer my latest questions?




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