2

I'm at the point now where I'm ready to dive into shaders, though I've been using a module based system as my means for learning how to do graphics programming (which I've written).

Since I'm working with D3D, I'd like to just make a shaders directory in my project root, store shaders there, and access them quickly.

There are obviously multiple ways to do this, but I don't have a very clear idea of obtaining my project's root directory. Is there a predefined macro for this - or a function of some sort for accessing a project's root folder?

zeboidlund
  • 9,731
  • 31
  • 118
  • 180
  • possible duplicate of [Get the application's path](http://stackoverflow.com/questions/218061/get-the-applications-path) – Deanna Jul 31 '12 at 10:31

2 Answers2

3

Most languages have a method to get the application path, but most will wrap the GetModuleFileName() function, passing a null module handle. You can then strip the executable name from the resulting path to get the base folder.

See this question for an extensive list of methods.

Community
  • 1
  • 1
Deanna
  • 23,876
  • 7
  • 71
  • 156
0
DWORD WINAPI [GetCurrentDirectory][1](
  __in   DWORD nBufferLength,
  __out  LPTSTR lpBuffer
);

Retrieves the current directory for the current process.

I believe this is the function you are looking for. You then append the subdirectory path that the shaders are located in respect to the full path returned that is where your program was executed from.

Deanna
  • 23,876
  • 7
  • 71
  • 156
gmlime
  • 1,017
  • 8
  • 17
  • I looked up that function, but won't that load to the actual binary directory of the program - instead of the source directory? – zeboidlund Jul 31 '12 at 04:17
  • In most projects enviroments, the binary directory is relative to the source directory, and thus you can use ".." to step back to a common root and then step forward to the location you are looking for, so for example "c:\projects\myproj\x64\bin\" + "..\..\source\shaders" – gmlime Jul 31 '12 at 04:28
  • 1
    Sorry but the "current directory" can be anything and potentially, bear no relation to the application directory. – Deanna Jul 31 '12 at 10:30