views:

534

answers:

3

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);
    glPushMatrix();
    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.

+2  A: 

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.

Brad Larson
1. Importing things won't fix a linker error. 2. The title says the questioner is using OpenGL ES on the iPhone.
Peter Hosey
You're right about the linker errors, I missed that. He does say "My target is currently a desktop app", so it looks to me like he's trying to use code intended for the iPhone on the Mac first. That might cause the linker problems with glOrthof().
Brad Larson
Oooh. Good catch.
Peter Hosey
Thanks for the help, a google search on `glOrthof` did not imply that it was an OpenGL-ES thing, I assumed it was the same for both.
Jacob
+1  A: 

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

Peter Hosey
As always, thanks for your invaluable help!
Jacob
A: 

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

nctrost