ogre3d 多系统配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LaineGates/article/details/80534855

参考ogre wiki:
获取执行路径—-GetExecutablePath
示例程序—-Basic+Ogre+Application
基础教程6—Basic+Tutorial+6

MAC

Mac osx的启动路径和windows/linux不一致,wiki推荐用如下函数:

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
 #include <CoreFoundation/CoreFoundation.h>

 // This function will locate the path to our application on OS X,
 // unlike windows you cannot rely on the current working directory
 // for locating your configuration files and resources.
 std::string macBundlePath()
 {
     char path[1024];
     CFBundleRef mainBundle = CFBundleGetMainBundle();
     assert(mainBundle);

     CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
     assert(mainBundleURL);

     CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
     assert(cfStringRef);

     CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
     CFRelease(mainBundleURL);
     CFRelease(cfStringRef);
     return std::string(path);
 }
 #endif

然后在启动时

int main() {
        // content ...
        #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
            resourcePath = Ogre::macBundlePath() + "/Contents/Resources/";
        #else
        resourcePath = "";
        #endif

        Ogre::Root* root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg", "Ogre.log");
        // reset content ...
 }

如果出现undefined _CFURLGetFileSystemRepresentation_CFBundleCopyResourcesDirectoryURLundefined _CFRelease等错误提示,给编译好的库添加-framework CoreFoundation
如果是cmake的话,可使用

target_link_libraries(program stdc++ "-framework Foundation" "-framework Cocoa" ...)

猜你喜欢

转载自blog.csdn.net/LaineGates/article/details/80534855