how to set image resource path for D3DXCreateTextureFromFileEx method?

This is a discussion on how to set image resource path for D3DXCreateTextureFromFileEx method? within the Game Programming forums, part of the General Programming Boards category; I try to merge all the image resources to a folder called resource. So, set image path as "resource/" but ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    127

    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)

    Name:  1.jpg
Views: 355
Size:  72.6 KB

    Code:
     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);
        }

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    I know this post is older but since no one has answered I will.

    I think if you set your working directory in your project to your bin folder then all of your relative paths will be correct regardless if you are running from the IDE or from Explorer. If your project runs inside of MSVS but does not run outside of it...it is almost always due to not having set the working folder inside of MSVS. You must make your environment in MSVS behave as if MSVS was not running and did not alter any paths. If you set your working folder to your bin and then base all of your relative paths off of that...your code will work both inside of MSVS and standalone.

    The problem arises in MSVS b/c even though your final output executable is in your specified output folder the actual environment within MSVS is relative to where the .sln is. Outside of MSVS everything is relative to where the executable is. So you must force MSVS to make all paths relative to your output folder instead of where your solution file is.
    Last edited by VirtualAce; 07-27-2013 at 02:18 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading image from Resource
    By parad0x13 in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2009, 10:36 PM
  2. Creating Icon resource using image
    By csonx_p in forum Windows Programming
    Replies: 2
    Last Post: 06-11-2008, 01:50 AM
  3. Loading Image from file path
    By csonx_p in forum Windows Programming
    Replies: 16
    Last Post: 04-25-2008, 07:38 AM
  4. Loading an image in from a resource file
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 06:44 AM
  5. How to Creating DLL image resource
    By nostromos in forum Windows Programming
    Replies: 1
    Last Post: 10-09-2005, 02:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21