ID3DXFont (DX 9.0c) square problems

ok, this is a really annoying problem

whenever i try to print text to the screen using the ID3DXFont::DrawText function, only squares appear

the thing is, i am using Arial font, so i don't think it can be that the computer doesn't know the font

sometimes however, a letter will appear somewhere in the line of text, but always in the wrong spot    it is always the last letter of the line though

i really really need some help here everybody, so any input at all would be appreciated




Answer this question

ID3DXFont (DX 9.0c) square problems

  • RHTCJohn

    do i need to explicitly undefine Unicode, or do i just not define it

    i think D3DXFONT_DESC may have been a previous version of directx 9, because with 9.0c, when i use it i get an error

  • ursus zeta

     Harry S wrote:
    Is placing an L in front of the string the only way to do it I want to put the DrawText function into another function, and I'm having trouble adding the L to the string when it is contained within a char* variable.

    The UNICODE macro controls whether or not Win32 and DirectX functions take Unicode strings by default.  You should make sure it's undefined if the rest of your code doesn't need to use Unicode.  Otherwise, you can use the D3DXCreateFontIndirectA() and DrawTextA() functions which explicitly use "char *" strings.

    btw.  this, and other problems in your code, are things that your compiler should have been complaining to you about.  For example, you shouldn't be using LOGFONT, but D3DXFONT_DESC instead.  If you have disabled any compiler warnings or errors you should seriously consider re-enabling them and fixing all the problems they're informing you about.

                                                            Ross Ridge


  • mbelew

    Can you post the relevant code

  • Vahid Nourbin

     Harry S wrote:
    do i need to explicitly undefine Unicode, or do i just not define it

    Just don't define it, but your compiler might be defining it automatically for you depending on how you've configured it.
     Harry S wrote:
    i think D3DXFONT_DESC may have been a previous version of directx 9, because with 9.0c, when i use it i get an error

    D3DXFONT_DESC is used by the DirectX 9 D3DX library, and LOGFONT is used by the DirectX 8 D3DX library.  Make sure you're including <d3dx9.h>.

    It's beginning to sound like your problem might be that you're compiling using headers that don't match the library you're linking with.  Try adding code something the following to your project:

    if (!D3DXCheckVersion(D3D_SDK_VERSION, D3DX_SDK_VERSION)) {
       MessageBox(NULL, "D3DXCheckVersion failed", NULL, MB_OK);
    }

     

  • Chris McCabe

     Harry S wrote:

    int iHeight = m_Font->DrawText(NULL, "hello", &Rect, DT_CENTER|DT_WORDBREAK, 0xFFFFFFFF);    

    and then all that turns up is "square square o square square"


    Sounds a lot like DrawText is interpretting your string as Unicode.  Try changing "hello" to L"hello".

    Ross Ridge


  • pr0gr4m3r

    Thank you so much for that

    Is placing an L in front of the string the only way to do it I want to put the DrawText function into another function, and I'm having trouble adding the L to the string when it is contained within a char* variable.

  • aze

    This is the font creation code:

    //Graphics->GetDeviceCOM() returns a initialized Direct3D device
    LOGFONT lf;

    // Clear out the font structure
    ZeroMemory(&lf, sizeof(LOGFONT));

    // Set the font name and height
    strcpy(lf.lfFaceName, "Arial");
    lf.lfHeight = -16;
    lf.lfWeight = 0;
    lf.lfItalic = FALSE;
    lf.lfUnderline = FALSE;
    lf.lfStrikeOut = FALSE;

    // Create the font object
    if(FAILED(D3DXCreateFontIndirect(Graphics->GetDeviceCOM(), &lf, &m_Font)))
      return FALSE;
    return TRUE;

    and then i try to draw the string "hello" to the screen with this:
    RECT rc;

    int Length = strlen("hello");

    SetRect(&Rect,0,0,65535,65536);
    int iHeight = m_Font->DrawText(NULL, "hello", &Rect, DT_CENTER|DT_WORDBREAK, 0xFFFFFFFF);    

    and then all that turns up is "square square o square square"      



  • ID3DXFont (DX 9.0c) square problems