How do I set up an OpenGL project using XCode 4.2 in C++?
Asked Answered
G

2

5

I am trying to get in to some graphics in C++. I figured it was best to start with the most capable graphics framework so I am going with the OpenGL included in Lion.

Basically I started a command line tool in C++ in XCode 4.2 and that's all I have done.

I need to somehow link OpenGL with the XCode so I can use it. After I get it set up on my Mac platform, I hope I can use a basic how-to guide for OpenGL for C++ to get further as, if you haven't noticed, I am not entirely clear on how to precede. Pretty much all I have read is some background information on how OpenGL uses the CPU and GPU together with the OpenGL client and server. I would appreciate any guide recommendations as well.

The question is: how do I link OpenGL with XCode 4.2 in C++ (not objective-c, it's funky) so I can use the graphics capabilities?

Gratuitous answered 3/1, 2012 at 3:43 Comment(1)
As XCode has updated to 4.5, the old step by step tutorial doesn't work, so I write an article for this: http://liangsun.org/posts/how-to-set-up-an-opengl-project-with-xcode/Albie
I
5

To use OpenGL in XCode you have to add the OpenGL framework to your project. Once that is done the header and library files will be available to the compiler and linker.

This page has a step by step tutorial for creating a C project that uses OpenGL and GLUT. If you are starting with OpenGL, then using GLUT might be a good idea, by the way. The tutorial will tell you to create a main.c file at some point. Instead, you have to create a main.cpp if you want to use C++.

Incendiary answered 3/1, 2012 at 4:51 Comment(1)
SFML or SDL is better than glut because it makes creating graphics applications fasterSubfusc
S
3

If you don't want to go the GLUT route just setup all your window and your base openGL context etc from objective C, then make calls to C++ functions from objective-C. You'll then be using objective-C++ which is fine. All you need do is name the objective-C++ bridge files with .mm, name any pure objective-C files with .m and your C++ implementation files .cpp and XCode should be happy.

As mentioned by Miguel, you'll still need to add the OpenGL framework to your project though...

Scarecrow answered 3/1, 2012 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.