Trap for ex-Windows GLUT programmers... -useWorkingDir |
1 January 2005 |
I use GLUT for my simple OpenGL projects. On Windows I use it and it always works.
When I ported a small project over to MacOSX it didn't work!
Isn't GLUT the same everywhere? Well, yes. The difficulty arose when reading files
after GLUT has been initialised. GLUT, when it starts up, sets the path to the
application's path. No problem you say, well ordinarily that would be right.
Windows has the application path where you expect, the Mac does not.
It's not that Mac OS X does it wrong, but that Mac OS X has a different
method for running and storing applications.
Try this on you Mac OS X machine: CTRL-CLICK on an application (Calculator)
and select "Show Package Contents",
select "Contents" in the new Finder window, select "MacOS", you are now at
the application's path.
1.
2.
3.
4.
My mistakes were not knowing about the path being set to the application path by GLUT,
and not realising that application paths were different in Mac OS X. I had looked at
application package contents before, just didn't think (aha!) about the difference here.
When I started to read my textures after GLUT was initialised my program would crash.
I got around this for "development time" by selecting the project's directory in the
info panel (APPLE+i) on the project's target executable:
-useWorkingDir
The Readme.txt included with the Mac OS X GLUT implementation has the following paragraph:
3) Normally, glut changes the working directory to the resources directory of
the applications package. This allows textures and other app resources
to be packaged with the application. GLUT will detect the lack of this
directory, such as with a non-packaged command line application and not
change the working directory. Additionally, added the ability to specify
a working directory option -useWorkingDir as a command line argument which
will also prevent GLUT from changing the initial working directory.
To solve this simply add -useWorkingDir as a parameter on the command line for the executable.
In Xcode "Get Info" on your executable, then select the "arguments" tab and add an argument for "-useWorkingDir".
Not at all obvious if you haven't read the GLUT readme.
|