This page looks best with JavaScript enabled

MacOS X and OpenGL

 ·  ☕ 3 min read  ·  🏍 Zisis

Introduction

Here is a guide on configuring an SFML, OpenGL, C++ project under Netbeans in MacOS X. I couldn’t find any similar guide on the net and I encountered some caveats and intricacies while trying to set it up. The lack of a complete guide alone made it worth blogging about.

First of all, I assume that NetBeans and SFML are already installed on your machine. If not, please go to the corresponding product’s official site and follow the guides there. They are pretty straightforward. Also make sure that Xcode has the command-line tools installed in order to ensure that the g++ compiler is properly installed and configured. Once everything is in place let’s start setting up the project.

Creating the NetBeans project

Open Netbeans and click on “File > New Project…”. From the available options select the “C/C++ Application” and click “Next”.
In the following screen provide a name for your project in the “Project Name:” textbox and click on “Finish”. The default values for remaining options should be just fine.

Configuring the needed libraries

We need to make visible SFML and OpenGL to both our source code and the linker before starting any actual work.

First of all we need to make visible to our code the header files of SFML and OpenGL, in order to be able to use both APIs. On your Project Window on the left, right-click on the project’s name and click “Properties”. Go to “C++ Compiler” and copy the following “/System/Library/Frameworks/OpenGL.framework/Headers:/Library/Frameworks/SFML.framework/Headers” in the “Include Directories” textbox. Click on the Apply button.

Right up next we need to guide the linker to the library files, otherwise messages of the type “cannot find the symbols defined” will populate the console. Go to “Linker”, click on “Libraries > Add Option > Add other option” and copy the value “-framework SFML -framework sfml-system -framework sfml-window -framework OpenGL”. This is a “tricky” part when setting up Netbeans on Mac OS because the –L option (which is used when adding libraries through the “Additional Library Directories”) simply does not work. Mac needs the -framework directive to guide it to the library files.

Sample Program Execution

Everything should be fine by now. Copy and paste the contents of the main function found here http://www.sfml-dev.org/tutorials/1.6/sources/window-opengl.cpp into the main method of our project an execute the program. You should be able to see a white rotating cube. If that’s the case OpenGL and SFML are set up successfully in your Mac/NetBeans configuration!

Additional configuration

Header files

In case you structure your code in multiple directories (and you’ll probably need that once you start working on something larger than the introductory all-in-one tutorial) you’ll need to add the folders where you keep your header files in the “C++ Compiler > Include Directories”. This way you’ll avoid the usage of relative paths in the inclusion of header files in your project files and the additional effort to change paths if you move header files from one place to another. This could get cumbersome as the project gets bigger.

Resource files

I also assume that you’ll also have resource files that need to be deployed along with the executable like configuration files, images, sounds etc. All you need is a little unix command line knowledge and a few edits in the makefile. Suppose that you have a keyboard.xml file under the folder (actual file system) <NETBEANS_PROJECT_FOLDER>/resources all you need to do is add the following line

1
cp resources/keyboard.xml ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/

in the makefile just below the .build-post: .build-impl goal

Notes

I’m completely new on NetBeans and relatively new on MAC so any comments are welcome. I’ve used NetBeans 7.2.1 C++ bundle and SFML 1.6 on Mac OS X 10.7.5.

Share on

Zisis Tachtsidis
WRITTEN BY
Zisis
Software Engineer, Husband to one, Father of two, Rider of two (motorcycles)