What I'd also like to see is platform independent utility functions to do the following:
* Get resource paths relative to each platform's default resource path.
* Save and load preferences in an operating system friendly way.
I do realise it's probably in the domain of GLFW or an equivalent API to do this, but if you have some resource utility functions why not have some more. Different operating systems have different conventions with file layout and it seems a lot of people on these forums myself included have been having trouble with resources not being found when running the demos.
On MacOSX it is recommended to use the API to find a resource's path given a filename, filetype, and optionally subdirectory. These resources are then found in a resource directory in a self contained app bundle. I think Horde3D could profit from having mechanisms to find resources like this, but in a platform independent way, like this:
Code:
lightPath = h3dResourcesGetPath("light.material", "xml", "materials/lights");
Additionally most operating systems have a means to store things like numbers, strings, and other settings in some form of associative array in a centrally managed location. This is User Defaults on OSX, probably in the registry on windows, and perhaps ~/.mysettingshere on Linux, it'd be nice to be able to save or load settings like this:
Code:
h3dSettingsSaveInt32("window.width", 800);
h3dSettingsStore();
I intend to do something like this, let me know if anyone wants to help, or if you think it will be useful to you.
This code is not what I'm describing, but related and might be useful to someone, it has been ripped from the demos and tries to be easy to integrate into them, it finds the resource path in an MacOSX app's bundle.
Code:
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#endif
std::string getDefaultBaseResourcesPath(int argc, const char * argv[])
{
if (argc == 0)
return NULL;
#ifdef __APPLE__
CFBundleRef bundle;
CFURLRef resourceDir;
CFURLRef absoluteResourceDir;
CFStringRef systemPath;
char * buffer;
size_t buffer_size;
// extract the resource path from the main bundle
bundle = CFBundleGetMainBundle();
resourceDir = CFBundleCopyResourcesDirectoryURL( bundle );
absoluteResourceDir = CFURLCopyAbsoluteURL( resourceDir );
systemPath = CFURLCopyFileSystemPath( absoluteResourceDir, kCFURLWindowsPathStyle );
// turn the resource path into a c string on the stack
buffer_size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(systemPath),
kCFStringEncodingUTF8);
buffer = (char*) alloca(buffer_size + 1);
CFStringGetCString(systemPath, buffer, buffer_size+1,
kCFStringEncodingUTF8);
// release temporary resources
CFRelease(systemPath);
CFRelease(absoluteResourceDir);
CFRelease(resourceDir);
return std::string(buffer) + "\\";
#else
const std::string s( argv[0] );
if( s.find( "/" ) != std::string::npos )
return s.substr( 0, s.rfind( "/" ) ) + "/";
else if( s.find( "\\" ) != std::string::npos )
return s.substr( 0, s.rfind( "\\" ) ) + "\\";
else
return "";
#endif
}