Search code examples
c++openglosx-mountain-lion

How do I create a c++ window on a mac?


How do I create a window using C++ on a Mac. Do I have to use openGL? I am using XCode, if that helps. I have tried to using the Windows, version but it did not work.

Any suggestions?


Solution

  • How do I create a window using C++ on a Mac

    That depends on the operating system installed ;) I guess you meant to ask "How do I create a window using C++ on MacOS X?"

    Do I have to use OpenGL?

    No. In fact OpenGL is on the opposite end of the equation. Before you can use OpenGL at all you first need a window, created with some other method than OpenGL.

    MacOS X makes extensive use of Objective-C and a set of class libraries with a Objective-C API known as Cocoa. Creating a window on MacOS X always involves writing some Obj-C code. But, it is perfectly possible to write a wrapper around that to provide a binding toward another language. Obj-C is a rather old language, but recently Apple created Obj-C++, which relates to Obj-C and C++ relates to C, i.e. you can use plain C++ language elements mixed with Objective constructs, which makes writing a C++ wrapper even easier.

    As for how to do it, and what details matter, this is too complicated to answer on StackOverflow. I suggest you read the source code of some framework library providing portable a window creation API.

    Due to their simplicity (not because the create an OpenGL window, that's actually a distraction in this case) I suggest you read into the relevant parts of the source code of SFML and GLFW