user32004
user32004

Reputation: 2403

Using C++ together with OpenGL in Xcode

My goal is to develop a cross-plattform based application in C++ and OpenGL.

Since I am using a Macbook Pro, its natural IDE is Xcode, so I would like to use it. I've successfully compiled pure C++ code in Xcode, by using the Command Line tool as a template for the projects.

My question is how can I compile OpenGL code without messing with Cocoa and Objective-C. The main reason behind this is that since I want to deploy cross-plattform applications, I want to stick to C++ as much as possible.

While this is true, It wouldn't be that much of a problem if I necessary had to use a little of Objective-C and Cocoa. But I would like to get my main project code in C++ and the less possible amount of Objective-C/Cocoa, understanding by "main project code" the code specific to my application, such as my classes, objects, and stuff related to the aim of the application, ie. , the main body of the code.

If using C++/OpenGL without messing with Obj-C/Cocoa is not worth in terms of complexity, then the question could be reformulated as simply what is the way to compile simple OpenGL code in Xcode?

Upvotes: 2

Views: 1116

Answers (3)

tiguero
tiguero

Reputation: 11537

Since Qt make it easy to make cross platform application it might be nice to consider this API. They have OpenGL module and you can set it up within XCode: http://qtnode.net/wiki/Qt4_with_Xcode.

Upvotes: 2

bames53
bames53

Reputation: 88155

OpenGL is a cross platform API, however it is very specific to performing graphics operations on an existing graphics context and does not encompass creating such a context or handling windowing events or anything else that requires integration with platform specific functionality. That is left to platform specific APIs.

Each platform's OpenGL implementation will include platform specific API's for performing the necessary tasks. Windows has WGL, X11 has GLX, and OS X has CGL at the low level or NSOpenGLView at the high level. OpenGL simply cannot be used without these platform specific APIs being used at some level. Furthermore, just getting a GUI of any kind requires this same sort of platform specific code.

There are projects which have wrapped various platform specific APIs in order to provide a portable API for creating a context and handling Windowing and other events outside the scope of OpenGL. One most commonly used when starting out with OpenGL is GLUT. OS X provides a framework with GLUT, however it has not been updated to use OS X's latest OpenGL support and is still stuck on OpenGL 2.x. There was a large change in the OpenGL API with the introduction of the OpenGL Core profile between 2.x and 3.x. This means that you can't currently use GLUT to write a modern OpenGL program on OS X.

Furthermore, by its cross-platform nature GLUT can never provide a decent GUI that conforms to the platforms' standards. Providing a decent GUI will always mean directly using platform specific APIs, or at least designing the GUI with the specific platform in mind.

Another difference between platforms is that on OS X you can use whatever version of OpenGL is supported just by including the standard OpenGL headers and calling functions and using identifiers as if using any other library. On Windows, the OpenGL headers don't provide anything past OpenGL 1.2, which is ancient, and using any OpenGL facility newer than that means accessing it via OpenGL's extension mechanism. There's another library, GLEW, that's aimed at making using OpenGL under these circumstances tolerable.

So OpenGL is a cross-platform API, but you will most likely need to use some amount of platform specific code around your core OpenGL code in order to use it effectively. GLUT probably would be a good cross-platform option, at least for learning OpenGL, except that it hasn't been updated on OS X to support the OpenGL Core profile introduced with OpenGL 3.x. But even with GLUT you'd have to deal with the differences in how OpenGL facilities are accessed, via the OpenGL extension mechanism or just directly via up-to-date headers.

Upvotes: 2

Aesthete
Aesthete

Reputation: 18850

OpenGL is well worth the time to learn. OpenGL is a C based, platform neutral API

Try starting here to learn the basics of GL.

I recommend using GLUT for you platform independent window work. Find that here

Using freeglut for you platform independent window work will help. Find that here

Upvotes: 0

Related Questions