3

I try to merge all the image resources to a folder called resource. So, set image path as "resource/" but my directX framework only works if I compile at VS 2010. If I run from the debug folder it cannot run.(I already copy all the image resources to debug folder)

https://i.stack.imgur.com/Shyj7.png

string folder = "resource/";

void setTexture(LPDIRECT3DTEXTURE9& texture, string imgName, int imgWidth, int imgHeight, D3DCOLOR TransparentColorKey)
{
    string path;

    path = folder + imgName;

    //  Create texture.
    hr = D3DXCreateTextureFromFileEx(d3dDevice, path.c_str(), imgWidth, imgHeight, 
        D3DX_DEFAULT, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 
        D3DX_DEFAULT, D3DX_DEFAULT, TransparentColorKey, NULL, NULL, &texture);
}
Edward A
  • 2,291
  • 2
  • 18
  • 31
user
  • 291
  • 2
  • 7
  • 18

2 Answers2

2

The default working directory when debugging from Visual Studio is the project directory and not the directory the executable is in. When using relative paths in your application you have to think about this and change the setting.

typ1232
  • 5,535
  • 6
  • 35
  • 51
0

Define the relative path to the directory 'resource' with respect to your project solution file (yourProjectName.sln) location not relative to your .exe file location.

SridharKritha
  • 8,481
  • 2
  • 52
  • 43