XCode 4

GLFW – Compiling Source and Creating an Xcode Project

GLFW is a great library – easy to use, great documentation covering it’s API design. But if you’re not on Windows where they provide pre-built libraries, going from a source download to a compiling Xcode project is _not_easy.

Since brew (as of writing) only provides GLFW 2, you need to build GLFW 3 yourself.

There is barely any information on it at all, it assumes you know exactly what you’ve downloaded (the source and some CMake files btw) and that you’ll be able to figure it all out (there is some additional information if you root around the GitHub forums but it’s not exactly easy to find).

So I’m posting up how I got GLFW to compile and running in Xcode here in-case anyone else starts banging their head against a brick wall.

First off, download the source followed by Cmake (I downloaded the 64/32-bit .dmg for 2.8.11.2).

Now to get it to compile you need to set up a few options. You can do this in the Cmake GUI, but I found it much easier to do it manually. Browse to GLFW/Src and open config.h.in.

This is a settings file for the compile you’re about to perform. There are a lot of settings in here you can play around with (they are explained in the README.md file in the root GLFW folder), but I enabled the following

  • _GLFW_COCOA
  • _GLFW_NSGL
  • _GLFW_NO_DLOAD_WINMM (this is a Windows only define, but I enabled it so adding it here anyway)
  • _GLFW_USE_OPENGL

 

Save the file and then you’re ready to compile.

Open the Terminal and browse to the root of the GLFW folder and enter the following commands

cmake .
make install

The Cmake command will set up the project ready to be built. It’ll take the config file we modified earlier and create a valid config.h file and it’ll carry out any other set up needed as well. ┬áCalling make builds the project, the install command installs the library in it’s default location.

Now you’re ready to add GLFW to your Xcode project. To keep it simple I’ll step through adding it to a new project, once you can do that adding it to an existing one is pretty easy.

  • Open Xcode and create a new OSX Command Line Tool project
  • In the project settings add the path to the GLFW include file in the ‘Header Search Paths’ and the path to the libglfw3.a lib to the ‘Library Search Paths’ option (both of these paths are shown in the install make output)
  • Add libglfw3.a to the Link build phase
  • You also need to add the following Frameworks to the build phase to allow the project to compile
    • IOKit
    • Cocoa
    • OpenGL

 

You can now copy/paste the sample code provided on the GLFW website into the existing main.c file, hit compile and you have a running GLFW project.

Note that the sample code doesn’t call glclear before glfwSwapBuffers so what you get in the open window is undefined.

Bug or Bad UI: Find and Replace in XCode 4

As applications get larger and more complicated with every iteration it sometimes becomes difficult to know if incorrect behaviour is down to a bug or badly designed user interface. XCode 4 is an application that has some quirky design choices, some which I really like and some which just baffle.

Here’s one a I found recently when trying something as simple as ‘Find and Replace’

Go to the search tab and search for something (preferably something that exists!). So in the following screenshot I’m searching for ‘defgroup’ which is a Doxygen documentation tab.

Now switch over to ‘Find’ and, as you would do if you did this a while later, change what you last searched for to what you want to replace. In this example, I’m now looking to change ‘client’ to ‘user’. Looking at the following screenshot, what would you expect to be replaced?

In my mind, I expected ‘client’ to be replaced with ‘user’. After all, that’s what I’ve put next to the Magnifying Glass icon – a universal icon for ‘search’ – and the results are for the last search I did, not this one.

But if I select Preview…

It’s actually replacing the results of the original search for ‘defgroup’ and not what I actually asked for, which was to replace ‘client’ with ‘user’. If I’d gone and selected Replace All then the same thing would have happened.

To get it to replace ‘client’ rather than ‘defgroup’ I need to either

  • Go back to Find search for ‘client’ then switch back to Replace and do it again
  • When entering the new search term, hit enter after typing ‘client’. This won’t do the replace, it’ll redo the search.

 

So, is this a bug or a failure of UI design? Should Preview and Replace All take what I’ve just put in the search box (in which case it’s a bug) or should it use what I last searched for (in which case it’s a UI issue).

Personally, I see this as a bug. As I work down the panel, I add what I what to replace with the new term then select Replace All. Since we read from left to right and top to bottom, information at the top of the screen is more important (the new term) than at the bottom (the results of the last search).

But then, some people could argue it’s a UI issue, and in that case an improvement to this work-flow from a UI perspective would cause this bug to never appear in the first place.