Thread: ID3DXFont not drawing

  1. #1
    ---
    Join Date
    May 2004
    Posts
    1,379

    ID3DXFont not drawing

    I have used ID3DXFont before but it was before I used this new code base and now I can't get it to work. All the font creation and drawing calls are working and I just can't see what's wrong.

    WinMain
    Code:
    /* Globals */
    const UINT g_iWidth = 1024;
    const UINT g_iHeight = 768;
    HWND g_hWnd;
    
    const char szClassName[ ] = "DirectX App";
    
    IDirect3D9 *g_pD3D;
    IDirect3DDevice9 *g_pDevice;
    d3d App;
    ID3DXFont *font = 0;
    char *font_name = "Times New Roman";
    
    
    int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){
      MSG msg;
      ::ZeroMemory(&msg,sizeof(MSG));
    
      if(!InitWindow(g_iWidth,g_iHeight,hThisInstance,nFunsterStil)){
        ::MessageBox(0, "InitWindow() - FAILED", 0, 0);
      }
    
      if(!App.InitD3D(g_hWnd, g_iWidth, g_iHeight, true, D3DDEVTYPE_HAL, &g_pD3D, &g_pDevice)){
        ::MessageBox(0, "InitD3D() - FAILED", 0, 0);
        return 0;
      }
    
      Setup();
    
      App.EnterMsgLoop(Display,msg);
    
      Cleanup();
      return msg.wParam;
    }
    Setup
    Code:
    bool Setup(){
      D3DXCreateFont(g_pDevice,
                     22,
                     0,
                     FW_NORMAL,
                     1,
                     false,
                     DEFAULT_CHARSET,
                     OUT_DEFAULT_PRECIS,
                     ANTIALIASED_QUALITY,
                     DEFAULT_PITCH|FF_DONTCARE,
                     "Arial",
                     &font);
    
      return true;
    }
    Display
    Code:
    bool Display(float timeDelta){
      RECT rect;
      SetRect(&rect,0,0,640,480);
    
      g_pDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0x77777777,1.0f,0);
      g_pDevice->BeginScene();
        font->DrawText(NULL,"Hello World!",-1,&rect,DT_LEFT|DT_NOCLIP,0x00000000);
      g_pDevice->EndScene();
    
      g_pDevice->Present(0,0,0,0);
      return true;
    }
    You probably don't ned to see this one but I'll show it just incase

    d3d::InitD3D
    Code:
    bool d3d::InitD3D(HWND hWnd, int width, int height, bool windowed,
                      D3DDEVTYPE deviceType, IDirect3D9 **D3D, IDirect3DDevice9 **device){
    
    
      *D3D = Direct3DCreate9( D3D_SDK_VERSION );
      if(!(*D3D)){
        return false;
      }
      D3DPRESENT_PARAMETERS d3dpp;
      ZeroMemory(&d3dpp,sizeof(d3dpp));
    
      d3dpp.BackBufferWidth = width;
      d3dpp.BackBufferHeight = height;
      d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
      d3dpp.BackBufferCount = 1;
      d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
      d3dpp.MultiSampleQuality = 0;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.hDeviceWindow = hWnd;
      d3dpp.Windowed = windowed; 
      d3dpp.EnableAutoDepthStencil = true;
      d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
      d3dpp.Flags = 0;
      d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
      d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    
      if(FAILED((*D3D)->CreateDevice(D3DADAPTER_DEFAULT, deviceType, hWnd,
                                  D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp, device))){
        (*D3D)->Release();
        D3D = NULL;
        return false;
      }
    
    
      return true;
    }
    Last edited by sand_man; 11-03-2005 at 05:30 PM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Your color param for DrawText is wrong, or at least not what you meant. You have 0x00000000, what you probably wanted was black text, fully opaque. That is to say, 0xFF000000. Be sure to mind the alpha component. Also, it's handy to use one of the many helpful color creation macros already available to you from DirectX (i.e. D3DCOLOR_XRGB ).
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    Thanks that was it.
    I never would have noticed that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing HBITMAP into CWnd, Acquired from "screenshot"
    By DeusAduro in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2009, 03:41 PM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  3. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 06:30 PM
  4. How to do double buffing with win32 drawing?
    By Josh Kasten in forum Windows Programming
    Replies: 2
    Last Post: 03-27-2004, 12:02 AM
  5. drawing minimaps and radar screens.
    By Eber Kain in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 11:44 AM