开发者

Using OpenGL ES functions on a Mac

I am trying to draw opengl into 2d space, and am doing the following, however it wont compile:

    int vPort[4];
    glGetIntegerv(GL_VIEWPORT, vPort);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glOrthof(0, vPort[2], 0, vPort[3], -1, 1);
    glMatrixMode(GL_MODELVIEW);
    g开发者_运维技巧lPushMatrix();
    glLoadIdentity();

I have included the OpenGL.framework framework, The compiler trace says the following.

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.


Have you included the appropriate headers?

On the Mac, these are

#import <OpenGL/OpenGL.h>

and possibly

#import <GLUT/GLUT.h>

On the iPhone they are

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


I have included the OpenGL.framework 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).

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.

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


You would just use glOrtho on vanilla GL. GL ES supports fixed and floating point data types, hence the glOrthox and glOrthof functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜