Search code examples
winapidirectoryshaderdirect3dresource-files

Getting the project directory in Win32 for shader loading


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?


Solution

  • 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.