Geeks With Blogs
Code.Blog Code Talk for the Game Developer
I've been struggling with this for probably the better part of a year and I feel it needs a bit of documentation.  The problem is that in my past demos I needed all my model and texture files in the same location as the EXE because I didn't know how to read from a different directory.  When loading something like a model, what you first do is store the current directory the computer is looking in (which is the base EXE directory).  Then you can switch the directory (locally) and read that in.  Then, when finished loading and doing whatever else you need, you can reset the directory to the original directory.  Here's a code snippet used to store the current directory and set it to a subfolder:

      TCHAR Buffer[MAX_PATH];
      GetCurrentDirectory(MAX_PATH, Buffer);
 
      std::string sData = "data";
 
      SetCurrentDirectory(sData.c_str());

Now you can repeat the SetCurrentDirectory() call for any other sub folder you need to go into.  In this case it goes into a subfolder named 'data'.  Then after you're done doing whatever you need to do (load models, create files, etc...), you can call the following to restore to the directory you stored in Buffer:

      SetCurrentDirectory(Buffer);
Posted on Tuesday, October 21, 2008 3:16 PM Tutorials | Back to top


Comments on this post: Loading From a Different Directory (C++ / DirectX)

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Matthew Christian | Powered by: GeeksWithBlogs.net