如何在 C++ 中使用 XCode 4.2 设置 OpenGL 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8707667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set up an OpenGL project using XCode 4.2 in C++?
提问by Eric Thoma
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.
我正在尝试使用 C++ 处理一些图形。我认为最好从功能最强大的图形框架开始,所以我将使用 Lion 中包含的 OpenGL。
Basically I started a command line tool in C++ in XCode 4.2 and that's all I have done.
基本上,我在 XCode 4.2 中用 C++ 启动了一个命令行工具,这就是我所做的一切。
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.
我需要以某种方式将 OpenGL 与 XCode 联系起来,以便我可以使用它。在我的 Mac 平台上设置好之后,我希望我可以使用 OpenGL for C++ 的基本操作指南来进一步了解,如果您还没有注意到,我对如何进行之前并不完全清楚。我所读到的几乎所有内容都是关于 OpenGL 如何将 CPU 和 GPU 与 OpenGL 客户端和服务器一起使用的一些背景信息。我也很感激任何指南建议。
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?
问题是:我如何将 OpenGL 与 C++ 中的 XCode 4.2(不是objective-c,它很时髦)链接,以便我可以使用图形功能?
采纳答案by Miguel
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.
要在 XCode 中使用 OpenGL,您必须将 OpenGL 框架添加到您的项目中。一旦完成,头文件和库文件将可供编译器和链接器使用。
This pagehas 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++.
此页面提供了创建使用 OpenGL 和 GLUT 的 C 项目的分步教程。顺便说一下,如果您从 OpenGL 开始,那么使用 GLUT 可能是一个好主意。本教程将告诉您main.c
在某个时候创建一个文件。相反,main.cpp
如果您想使用 C++ ,则必须创建一个。
回答by Michael Anderson
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.
如果您不想走 GLUT 路线,只需从目标 C 设置所有窗口和基本 openGL 上下文等,然后从目标 C 调用 C++ 函数。然后你将使用objective-C++,这很好。你需要做的就是用 .mm 命名目标 C++ 桥文件,用 .m 命名任何纯目标 C 文件,你的 C++ 实现文件 .cpp 和 XCode 应该很高兴。
As mentioned by Miguel, you'll still need to add the OpenGL framework to your project though...
正如 Miguel 所提到的,您仍然需要将 OpenGL 框架添加到您的项目中...