   [Solved] D3DXFont drawn text not showing up.
  I've created a font class that just uses basic D3DXFont functions. Very simple but for some reason it's not showing up when I try and use it to render text in my DX app. Here is code from the font class:bool CFont::InitFont(IDirect3DDevice9* device, char* fontName, int weight){LOGFONT logFont;ZeroMemory(&logFont, sizeof(LOGFONT));logFont.lfHeight = 50;logFont.lfWidth = 50;logFont.lfWeight = weight;logFont.lfItalic = false;logFont.lfStrikeOut = false;logFont.lfUnderline = false;logFont.lfCharSet = DEFAULT_CHARSET;strcpy(logFont.lfFaceName, fontName);HRESULT debug = 0;debug = D3DXCreateFontIndirect(device, (D3DXFONT_DESC*)&logFont, &m_pFont);if(FAILED(debug)){MessageBox(NULL, "Failed to create font.", "Error!", MB_OK);return false;}return true;}void CFont::Draw(char* string, int x, int y, DWORD color){RECT drawRect;drawRect.left = x;drawRect.top = y;drawRect.right = x + 500;drawRect.bottom = y + 500;if(m_pFont)m_pFont->DrawTextA(NULL, string, -1, &drawRect, DT_TOP | DT_LEFT, color);}and here is when it is actually used in my main application:char buffer[32];memset(buffer, 0, 32);sprintf(buffer, "Frame Rate: %d", m_iframeRate);m_pFont->Draw(buffer, 20, 20, D3DCOLOR_XRGB(255, 0, 0));Any ideas?[Edited by - ChaosPhoenix on December 13, 2005 12:35:30 AM]
  Try calling :D3DXFont::Begin() D3DXFont::DrawText()D3DXFont::End()(Altough its said in the SDK that if you don't call begin/end Direct3D will do it for you, try putting them yourself and let me know if it worked);  D3DXFont doesn't have begin and end scene functions, but I place it between my begin and end scene calls in my rendering code anyway.m_pD3DDevice->BeginScene();...Rendering objects code...if(GetTickCount() - m_iframeTimer > 1000){char buffer[32];memset(buffer, 0, 32);sprintf(buffer, "Frame Rate: %d", m_iframeRate);m_pFont->Draw(buffer, 20, 20, D3DCOLOR_XRGB(255, 0, 0));m_iframeTimer = 0;}elsem_iframeRate++;m_pD3DDevice->EndScene();m_pD3DDevice->Present(NULL, NULL, NULL, NULL);;  As I remember the y axis for directx drawing is pointing up (your screen (0,0) is at the bottom left) so your bottom right point for your rectangle should be (x+500, y-500)(I'm not sure about this since its been a time since I used it, but give it a try anyway :))   ;Quote:Original post by DesignerXAs I remember the y axis for directx drawing is pointing up (your screen (0,0) is at the bottom left) so your bottom right point for your rectangle should be (x+500, y-500)(I'm not sure about this since its been a time since I used it, but give it a try anyway :))D3DXSprite objects(what D3DXFont renders to) use the same coordinate system as the Windows GDI(0,0 is the top left of your screen, pos x to the right, pos Y to the bottom) as far as I am aware. I'm at work but I'll try this out for kicks when I get back home.Till then, keep the suggestions coming.   ;  Try :1. The ID3DXFont interface (is there a D3DXFont interface ???) does have a begin and end methods (look at the SDK)2. Why are you using DrawTextA and not DrawText ? why are you passing a nullas the first parameter ?, I mean DrawTextA is defined as :INT DrawTextA(LPCSTR pString,    INT Count,    LPRECT pRect,    DWORD Format,    D3DCOLOR Color);3. I don't know what the GetTickCount() methods does, but maybe you aren't evenreaching the code inside the "if". (Debug and see if your program reaches the m_pFont->Draw(buffer, 20, 20, D3DCOLOR_XRGB(255, 0, 0)) line)Hope one of the above will help finding the problem ;);Quote:Original post by DesignerXTry :1. The ID3DXFont interface (is there a D3DXFont interface ???) does have a begin and end methods (look at the SDK)2. Why are you using DrawTextA and not DrawText ? why are you passing a nullas the first parameter ?, I mean DrawTextA is defined as :INT DrawTextA(LPCSTR pString,    INT Count,    LPRECT pRect,    DWORD Format,    D3DCOLOR Color);3. I don't know what the GetTickCount() methods does, but maybe you aren't evenreaching the code inside the "if". (Debug and see if your program reaches the m_pFont->Draw(buffer, 20, 20, D3DCOLOR_XRGB(255, 0, 0)) line)Hope one of the above will help finding the problem ;)The SDK you were looking at must of been for DX8. DX9 removed the begin and end calls from ID3DXFont.I changed DrawTextA to DrawText. DrawText is just a macro that calls DrawTextW for Unicode by default. DrawTextA just says I'm drawing ASCII so screw unicode. Still didn't change anything however. The NULL parameter I pass in is for the sprite object that the font will write to. If you pass it NULL, it creates a sprite object for you.From the DX9 SDK:INT DrawText(LPD3DXSPRITE pSprite,    LPCTSTR pString,    INT Count,    LPRECT pRect,    DWORD Format,    D3DCOLOR Color);pSprite[in] Pointer to an ID3DXSprite object that contains the string. Can be NULL, in which case Microsoft Direct3D will render the string with its own sprite object.I know the GetTickCount() method(which is a framerate counter btw) works because I've been using it with SetWindowText. I've just been reporting my framerate as my window title until I could get a font class up. So, I know it's fine. I've even place in break points and everything gets called correctly, everything returns succesful values, yet nothing shows up on the screen.   ;  Chaos,Are you using the ID3DXSprite as well? if you are using the interface then as far as i know the draw calls are cumulated until the End() sprite function is called. Try using the End() just before you draw the text, and then begin() again - not the quickest way to handle things, but a test to see if thats your problem.Also, Check the return value of DrawText - it should return the height of the drawn text.Alex   ;  I tried giving it it's own Begin and End scene and it didn't change anything. But I doubt it would of in the first place. From the DX9 SDK for DrawText:This method must be called inside a IDirect3DDevice9::BeginScene ... IDirect3DDevice9::EndScene block.The return value is constantly 15. Which is +1 to my original specified height(I do -16 and it takes the absolute value). I have literally copied font descriptors from the SDK example and it doesn't change a thing. The only thing I can think of is there is something wrong with my RECT in the draw fuction, but I have no clue what.   ;  I found the issue. It was a logic error. I was literally calling that draw text function for a single frame.It works now, just gotta play with some style changes now.   