在Mac上使用OpenGL ES功能

Jac*_*cob 6 macos xcode opengl-es

我试图将opengl绘制到2d空间,并且正在执行以下操作,但它不会编译:

    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();
Run Code Online (Sandbox Code Playgroud)

我已经包含了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
Run Code Online (Sandbox Code Playgroud)

我已经没有关于如何解决它的想法.我的目标是目前的桌面应用程序,但我的目标是最终制作一个iPhone应用程序.

Bra*_*son 6

你有没有包含适当的标题?

在Mac上,这些是

#import <OpenGL/OpenGL.h>
Run Code Online (Sandbox Code Playgroud)

可能

#import <GLUT/GLUT.h>
Run Code Online (Sandbox Code Playgroud)

在iPhone上他们是

#import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
Run Code Online (Sandbox Code Playgroud)

另外,如果我没弄错的话,glOrthof()是特定于OpenGL-ES的.您可能需要在Mac上使用glOrtho().

  • 1.导入内容不会修复链接器错误.标题说提问者在iPhone上使用OpenGL ES. (2认同)
  • 哦.接得好. (2认同)