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

自闭症网瘾萝莉.ら 提交于 2019-12-21 14:57:21

问题


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?


回答1:


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++.




回答2:


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...



来源:https://stackoverflow.com/questions/8707667/how-do-i-set-up-an-opengl-project-using-xcode-4-2-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!