ogre3d 多系统配置

参考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" ...)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值