# how to set image resource path for D3DXCreateTextureFromFileEx method?

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)

http://i.stack.imgur.com/XRFLC.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);
}


A simple way would be to configure your output directory for your project and then set your working directory to that folder.

1) Set your output directory. This folder holds your .exes, .liks and .pdbs. In this example I will output to a folder called Bin outside of my project directory.

2) As you are outputting to a folder for multiple configs, you will want to modify your target name so they can be distinguished between debug and release. In this example I have appended _debug to my Target Name for my Debug config and _release for my Release config so that when I build both configs there will be two sets of files for each config.

So now you will have a folder storing your exe outside of your project root.

3) Create your Resource folder in the same directory as your Bin and Project. The folder structure will look something along the lines of:

 -- DirectX FrameWork
|-- Bin
|-- Project
|-- Resources


Now as you can see, when you run from Visual Studio or the .exe they will both be using the same working directory, so the same relative file path can be used when referencing files. Doing this also helps to separate your code from your resources.

There are multiple things that can cause this but maybe try this, if that doesn't work please provide us with more information about the project and deployment setup

When running via Visual Studio the CWD (current working directory) is that of the project (by default) so the path to your files is "./resource/" while if you're running from the debug folder your CWD is that of the executable, so the path to the resources is "./../resource/".

You have to set up that your resources are copied to the output directory. You can do this in the solution explorer by selecting the resource and selecting "Copy To Output Directory"

• Why it goes to property pages after I click properties? i.stack.imgur.com/ok6Fe.png
– user
Jul 13 '13 at 8:09
• That is weird, as what kind of file type have you added the png? (Resource, Content, ...?) Jul 13 '13 at 8:14
• yup. I add png image file into resource folder
– user
Jul 13 '13 at 8:28
• Ok. Now I can show file properties but I dun have advanced section. i.stack.imgur.com/GXOFl.png
– user
Jul 13 '13 at 8:33
• I'm very curious why this answer was voted down at least twice, are there any errors? I think it is a plausible answer given the tiny bit of information in the question. Jul 14 '13 at 10:25