I'm working on a small DX9 game project for learning purpose. I'm current dealing with resources manager file (*.rc) which i'm not used to (Because I have only worked with direct file until now). If I use D3DXLoadSurfaceFromFile , It worked fine, the image was drawn on windows. When I changed to D3DXLoadSurfaceFromResource, I think it can not load the image, only a black screen (The Hresult that it return is S_FALSE)

This is the create surface function :

bool Surface::CreateSurface()
    if (FAILED(m_Device->CreateOffscreenPlainSurface(
        return false;

    if (FAILED(D3DXLoadSurfaceFromResource(
        return false; // S_FALSE and return false while debug
    return true;

This the render function :

void GWindow::Render()
    Surface Hello_Brown(146, 146, m_lpD3DV, IDB_SAMPLE); // IDB_SAMPLP will be assigned to m_RsSymbol
    LPDIRECT3DSURFACE9 backbuffer;
    if (NULL == m_lpD3DV)

    m_lpD3DV->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);



    m_lpD3DV->Present(NULL, NULL, NULL, NULL);

Where I am wrong and how to fix it?

Update resource file : link

i bring it to an online text, because it too long to write here

  • \$\begingroup\$ Can you post your .rc file too, please? And verify that the bitmap resource is being compiled into the executable. \$\endgroup\$ – Maximus Minimus Aug 6 '16 at 9:56
  • \$\begingroup\$ I have update the .rc file, the ICON_GWINDOW is loaded success as app icon, so i think all files a loaded. \$\endgroup\$ – Hai Hoang Aug 6 '16 at 11:22
  • \$\begingroup\$ Note that both Direct3D 9 and D3DX are deprecated, along with the legacy DirectX SDK itself. I'd recommend you look at using Direct3D 11 instead unless you have some specific OS limitation that forces you to use a 12+ year old API. See MSDN \$\endgroup\$ – Chuck Walbourn Aug 6 '16 at 21:32
  • \$\begingroup\$ In my country, they're still using DX9 for teaching Basic game programing (game logic, collision detection, quad tree, etc...) due to lacking of many thing. After passed this subject, i want to practice more with the core of game programing before using an engine, so i choose continue with DX9. Thank for your advise, i will take a look at DX11. \$\endgroup\$ – Hai Hoang Aug 7 '16 at 3:44
  • \$\begingroup\$ Many educational settings have labs that are still running Windows XP or Windows 7, and of course curricula can take a long time to change. Direct3D 9 definitely has a lot of limitations these days (no debugging support on Windows 8.x or later, appcompat behaviors to simulate Windows XP, etc.). If you can, using Direct3D 11 will give you a much smoother experience. You might want to take a look at DirectX Tool Kit for DirectX 11 and the tutorials in particular. \$\endgroup\$ – Chuck Walbourn Aug 18 '16 at 16:31

This is failing because the resources in your .rc are of the wrong type. See the documentation for D3DXLoadSurfaceFromResource:

The resource being loaded must be of type RT_BITMAP or RT_RCDATA. Resource type RT_RCDATA is used to load formats other than bitmaps (such as .tga, .jpg, and .dds).

Your incorrect entry:

IDB_MARIO               PNG                     "Resouce Files\\Images\\Mario.png"

And the correct equivalent:

IDB_MARIO               RCDATA                  "Resouce Files\\Images\\Mario.png"

By convention a resource of type RCDATA also has it's name prefixed with IDR_ rather than IDB_ (or anything else), but since this is just a #define in your resource.h it most likely doesn't matter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.