tags:

views:

115

answers:

5

Hi,

I normally program on Windows, but I got a macbook pro from my school, so I'm trying to make an OpenGL app for OSX. I downloaded and installed XCode, but I have no clue how to get a simple OpenGL app going. I would prefer not to use Objective-C, but I definitely don't want to use GLUT. Can someone point me in the right direction?

A: 

You'll learn Objective C, and you'll learn to like it. Apple Developer Connection

mcandre
haha, well played!
Alan
yea, that doesn't answer my question. nor is that constructive. The Apple docs are pretty crappy. I'm just looking for a way to create a window and initialize OpenGL.
Ernesto Rojo Jr
Give in to apple...
jacortinas
Apple's docs aren't really a primer for OpenGL; they're instructions on how to use the Cocoa OpenGL views.
mipadi
@Ernesto: I think it was meant to be a humorous answer. But, @mcandre has a point, if you want to be really successful in OSX, and transition to iOS platforms, you are hampering yourself by not learning Objective-C.
Alan
I learned Objective-C for work a couple of months ago. I find it way too verbose. It's very confusing to read. So I try to stay away from it like the plague.
Ernesto Rojo Jr
@Ernesto: then you probably should stay away from Mac programming. All neat modern stuff Apple does is done in ObjC and is available generally only via Cocoa. If you do not like it then do not do it. And its documentation is definitely better than that of MS (CHM v. PDF alone make the hell of a difference). E.g. OpenGL has premade component in Cocoa you need only to instantiate. I used official tutorials and could code a Solitaire in a week or so.
Dummy00001
Then if I want to get anything done, I should use Carbon? I heard Carbon uses a c/c++ interface, right? Sounds closer to what I'm looking for. Personally, I haven't seen any documentation that beats the MSDN. But you have your opinion and I have mine.
Ernesto Rojo Jr
Use QT. Carbon is awful.
James Roth
+1  A: 

When using OpenGL on Mac OS X, there are two things to keep in mind:

One, you have to link the OpenGL framework. Outside of Xcode, you can pass the -framework flag to the linker:

$ gcc -framework OpenGL -o my_opengl_program my_opengl_program.c

(Note that this flag only works on OS X.)

If you're using Xcode, you can just add OpenGL.framework to your linked frameworks.

Two, you prefix OpenGL/> in front of your OpenGL headers. For example, to include gl.h, use:

#include <OpenGL/gl.h>

Otherwise, programming with OpenGL on Mac OS X is pretty much the same.

mipadi
I don't think you understand the spirit of the question. I'm pretty sure that, after doing the above, I won't be calling wglCreateContext. What I'm looking for is either skeleton code for creating a window and attaching a OGL context to it or some pseudocode that explains the procedure.
Ernesto Rojo Jr
Seeing as how `wglCreateContext` is specific to Windows (as far as I know), then no, you wouldn't be using that on Mac OS X. However, you can use *just* the OpenGL functions to write an OpenGL program on OS X.
mipadi
right, i know the OpenGL functions don't change. that wasn't the original question, but some of the info you gave is definitely relevant, so thank you for that.
Ernesto Rojo Jr
Your original question asked how you get a "simple OpenGL app" running on OS X without using Objective-C.
mipadi
A: 

Since you're programming on a mac, you can use any language you're familiar with. XCode supports compiling C++, so if you're familiar with OpenGL on windows, then it's a straight forward transition, though you will need to use the proper methods for creating an OSX Window (cocoa most likely).

If python is your thang, PyOpenGL is a python binding to OpenGL that is cross platform.

Alan
You can use the OpenGL primitives for creating/working with windows directly (no need to go through Cocoa per se).
mipadi
+2  A: 

The biggest difference between OpenGL on OS X compared to pretty much everything else is the location of the header files. On OS X:

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

If you want to stay away from Objective-C/Cocoa and GLUT you can try SDL which is a cross platform gaming library (windows, 2D graphics, sound, input, etc.).

Edit: forgot about the compiler flags, which mipadi posted, namely:

-framework OpenGL
Niki Yoshiuchi
I was considering SDL. I've used it before in a student project. But I want to learn the steps needed to create a window and then initialize OpenGL. I dont want to go through Interface Builder or have Cocoa automagically create a window for me.
Ernesto Rojo Jr
Seems like I'm gonna go with the SDL route. Can't seem to find exactly what I'm looking for.
Ernesto Rojo Jr
Well Cocoa is the API for Mac OS X development, so I'm not sure how that's "automagic." You use Cocoa to create a window in OS X just like you use the Windows API to create a window in Windows.
Niki Yoshiuchi
Right, I meant the way Interface Builder creates the nib that NSApplicationMain uses to magically create the window. If I can create the window manually w/o using IB, that would be great. The next step after that would be to create the OpenGL context and use that to draw on. I'm looking for that process, but for the mac. I don't want things to be hidden from me. I want to SEE the creation process step by step.
Ernesto Rojo Jr
Ah, gotcha. I'm sure it possible to do it directly but alas, my OS X development knowledge is basically nil. I know enough to get OpenGL and SDL running and from there it's pretty much the same as any other platform. I did however find this series of blog posts about developing OS X apps without a NIB: http://lapcatsoftware.com/blog/2007/05/16/working-without-a-nib-part-1/
Niki Yoshiuchi
You can use the same OpenGL primitives for creating windows on Mac OS X as you use on other platforms.
mipadi
A: 

The non-Objective C library is AGL.

James Roth