1 pixel image
1 pixel image

Code blog.

Here you will be able to download free source code, read about some of our coding experiences and learn some handy hints. The archives normally contain source in a mixture of C, Objective-C and C++, XML datafiles, required graphics and sounds and occasionally a Doxygen config file.

We use (and recommend) OpenGL and TinyXML, a great light XML parser.


1 pixel image
1 pixel image
most recent

January 2005

email jeroen
1 2 3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
1 pixel image
1 pixel image

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.Show Package Contents Menu 2.Calculator App Dir

3.Contents Dir 4.Application Dir

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:

General tab.

-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".

Arguments tab.

Not at all obvious if you haven't read the GLUT readme.




  

Archive

  May 2007
  April 2007
  ...
  2006? Oh, we missed it.
  ...
  October 2005
  September 2005
  August 2005
  July 2005
  June 2005
  May 2005
  April 2005
  March 2005
  February 2005
  January 2005
  December 2004
  November 2004
  October 2004
  September 2004
  August 2004