xcode 在 Mac 上使用 OpenGL ES 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1999226/
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
Using OpenGL ES functions on a Mac
提问by Jacob
I am trying to draw opengl into 2d space, and am doing the following, however it wont compile:
我正在尝试将 opengl 绘制到二维空间中,并且正在执行以下操作,但是它无法编译:
int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrthof(0, vPort[2], 0, vPort[3], -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
I have included the OpenGL.framework framework, The compiler trace says the following.
我已经包含了 OpenGL.framework 框架,编译器跟踪说明如下。
In function '-[OpenGLView drawRect:]':
warning: implicit declaration of function 'glOrthof'
Ld build/Debug/OpenGLTest1.app/Contents/MacOS/OpenGLTest1 normal x86_64
/Developer/usr/bin/gcc-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk - L/Users/user/Documents/cocoa/OpenGLTest1/build/Debug -F/Users/user/Documents/cocoa/OpenGLTest1/build/Debug -filelist /Users/user/Documents/cocoa/OpenGLTest1/build/OpenGLTest1.build/Debug/OpenGLTest1.build/Objects-normal/x86_64/OpenGLTest1.LinkFileList -mmacosx-version-min=10.6 -framework Cocoa -framework OpenGL -o /Users/user/Documents/cocoa/OpenGLTest1/build/Debug/OpenGLTest1.app/Contents/MacOS/OpenGLTest1
Undefined symbols:
"_glOrthof", referenced from:
-[OpenGLView drawRect:] in OpenGLView.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I've run out of ideas on how to fix it. My target is currently a desktop app, but I am aiming to make an iphone app eventually.
我已经没有关于如何修复它的想法了。我的目标目前是一个桌面应用程序,但我的目标是最终制作一个 iphone 应用程序。
回答by Brad Larson
Have you included the appropriate headers?
您是否包含了适当的标题?
On the Mac, these are
在 Mac 上,这些是
#import <OpenGL/OpenGL.h>
and possibly
并且可能
#import <GLUT/GLUT.h>
On the iPhone they are
在 iPhone 上,它们是
#import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
Also, if I'm not mistaken, glOrthof() is OpenGL-ES-specific. You may need to use glOrtho() on the Mac.
另外,如果我没记错的话,glOrthof() 是特定于 OpenGL-ES 的。您可能需要在 Mac 上使用 glOrtho()。
回答by Peter Hosey
I have included the OpenGL.framework framework…
我已经包含了 OpenGL.framework 框架......
You don't include frameworks. You include (or import) headers and link against frameworks. Relatedly, only the warning in your output comes from the compiler; everything after it comes from the linker (ld
).
你不包括框架。您包含(或导入)标头并链接到框架。相关地,只有输出中的警告来自编译器;它之后的所有内容都来自链接器 ( ld
)。
The compiler and linker aren't complaining that any other of those functions don't exist, so your problem is simply that that function doesn't exist. Because it doesn't exist, it isn't declared in the header (hence the compiler warning) or exported by the framework (hence the linker error).
编译器和链接器不会抱怨这些函数中的任何其他函数不存在,所以您的问题只是该函数不存在。因为它不存在,所以它没有在头文件中声明(因此是编译器警告)或由框架导出(因此是链接器错误)。
Make sure you're using the OpenGL framework from the iPhone SDK, not from your (Mac OS X) System folder. They're different, and I know my Mac OS X OpenGL.framework doesn't have a glOrthof
function. Remove the OpenGL framework you have in your project now, and add the iPhone OpenGL framework using the “Add Existing Frameworks” command that appears when you right-click on a group in your Xcode project.
确保您使用的是来自 iPhone SDK 的 OpenGL 框架,而不是来自您的 (Mac OS X) 系统文件夹。它们是不同的,我知道我的 Mac OS X OpenGL.framework 没有glOrthof
功能。现在删除项目中的 OpenGL 框架,然后使用“添加现有框架”命令添加 iPhone OpenGL 框架,该命令在您右键单击 Xcode 项目中的组时出现。
My target is currently a desktop app, …
我的目标目前是一个桌面应用程序,...
Then you're going to need to find a replacement for that glOrthof
function, because it doesn't exist on the Mac. (Thanks to Brad Larson for pointing this part of the question out.)
然后您将需要找到该glOrthof
功能的替代品,因为它在 Mac 上不存在。(感谢 Brad Larson 指出问题的这一部分。)
回答by nctrost
You would just use glOrtho on vanilla GL. GL ES supports fixed and floating point data types, hence the glOrthox and glOrthof functions.
您只需在 vanilla GL 上使用 glOrtho。GL ES 支持定点和浮点数据类型,因此有 glOrthox 和 glOrthof 函数。