Using ID3DXSprite in ID3DXFont DrawText()
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()?
here this should work for you
this is just a function to load a font
And sample of how to load a sprite and use it to draw text
Hope that solves your issues
this is just a function to load a font
// Function for font loadingHRESULT 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 textpFont->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 spritem_pD3dDevice->EndScene();
Hope that solves your issues
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?
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?
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.
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()?
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()?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement