OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: ProjectPaths
View page
Source of version: 3
(current)
!!Introduction Applications are built differently on Mac and on Win/Linux. On Win/Linux, you have your binary file on top with your Media folder and even config files : {CODE(wrap="1", colors="c++")}|MyApp.exe |Media| |materials | |... |ogre.cfg |...{CODE} On Mac, it's a bundle system, so that everything is packed into the bundle (*.app). Of course you can choose not to respect that and make your project like on Win/Linux. But the cleaner way (and the usual way for OSX users) is the bundle : {CODE(wrap="1", colors="c++")}|MyApp(.app)| |Contents| | |MacOS| | | |MyApp (binary file) | | |Resources| | | | *** here goes all your stuff : medias, plugins, ... ***{CODE} !!How Can I get the path to my application ? This very useful information is provided by a small method (given in the Ogre Mac release) : {CODE(wrap="1", colors="c++")}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);{CODE} On Windows, you can use the method outlined in ((GetExecutablePath)). For Linux, if you want to release your project using any of the major packaging systems such as rpm or deb it is generally preferred to hardcode the path or prefix at compile time. If you want to provide relocatable releases for Linux the [http://www.autopackage.org/|Autopackage] project provides a tool called [http://www.autopackage.org/download-tools.html|Binreloc] which allows for this. !!And what about cross platform projects ? Yes yes, we're getting there... You can make it usable only on Mac with guard : {CODE(wrap="1", colors="c++")}#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE{CODE} So, a good way of getting you application path on every system is : {CODE(wrap="1", colors="c++")}std::string bundlePath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 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); #else return "" ; #endif }{CODE} Then, in your code, just call the bundlePath() to get the bundle/application folder. !!And if I want my media folder then ? The thing couldn't be easier... Just define another function to get your Media folder : {CODE(wrap="1", colors="c++")}std::string mediaPath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE return bundlePath() + "/Contents/Resources/Media/" ; #else return bundlePath() + "/Media/" ; #endif }{CODE} !!And in the code ? Isn't a bit messy ? Not at all... Create a file (Paths.h for example) and put into it all your necessary functions for paths. Then in your, include this file, and just call the methods your need. The good point is that in the code, you don't have to worry anymore about the plateform you are on ! Example => I created a logsPath function : {CODE(wrap="1", colors="c++")}std::string logsPath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE return bundlePath() + "/Contents/Resources/Logs/" ; #else return bundlePath() + "/Logs/" ; #endif }{CODE} Then in my custom Log class, I just call : {CODE(wrap="1", colors="c++")}string filePath = logsPath() + filename ;{CODE} !!Conclusion It's not really hard to have thing well set up for cross plateform project. Just do it well at start and it will make your code easier to understand (and to make too). Moreover, this concept make your code more flexible with paths. If you have any remarks, please pm __fp12__ on the forum ;) !!Sample file {CODE(wrap="1", colors="c++")}#ifndef Paths_h #define Paths_h #include <OGRE/OgrePlatform.h> std::string bundlePath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 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); #else return "" ; #endif } std::string logsPath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE return bundlePath() + "/Contents/Resources/Logs/" ; #else return bundlePath() + "/Logs/" ; #endif } std::string configPath() { #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE return bundlePath() + "/Contents/Resources/" ; #else return bundlePath() ; #endif } #endif {CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
316 online users