PDA

View Full Version : Programmatically creating an OpenGL window




Starfox
Jun 20, 2011, 05:16 PM
I'm porting some code over to OS X from Win32 and some other platforms, and it's almost all ported except for functions that create / destroy and OpenGL window - how could I do that in OS X? I started with a foundation app as a sandbox to test my code in but there doesn't seem to be a lot of documentation regarding this specific case. Any help would be appreciated.



jiminaus
Jun 20, 2011, 06:25 PM
Drop an OpenGL view onto your window. If you don't know Objective-C and Cocoa, perhaps use the C-based OpenGL Utility Toolkit (GLUT).

For more info about Open GL on Mac OS X, see the OpenGL Programming Guide for Mac OS X (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide).

Cromulent
Jun 20, 2011, 06:33 PM
Drop an OpenGL view onto your window. If you don't know Objective-C and Cocoa, perhaps use the C-based OpenGL Utility Toolkit (GLUT).

For more info about Open GL on Mac OS X, see the OpenGL Programming Guide for Mac OS X (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide).

If you are not using Cocoa then I highly recommend SDL over GLUT. In fact I would recommend cutting your own leg off instead of using GLUT. GLUT has not been updated for many years, has basic functionality at best and is generally rubbish.

chrono1081
Jun 20, 2011, 07:03 PM
If you are not using Cocoa then I highly recommend SDL over GLUT. In fact I would recommend cutting your own leg off instead of using GLUT. GLUT has not been updated for many years, has basic functionality at best and is generally rubbish.

I completely agree with this. GLUT cannot easily be abstracted into a class like SDL can. I ran into a HUGE problem in a class I had where we had to write a game engine. I picked OpenGL and GLUT not realizing GLUTs limitations until it was too late.

Starfox
Jun 20, 2011, 07:32 PM
Let me tell you this: as a pro, I'd rather be stabbed than use SDL. Its design is full of hacks (FFS, it #define-s 'main'!), memory allocations at bad times and just plan stupidity.

GLUT isn't bad for prototyping a shader or a render-path quickly but I wouldn't use it for a full-fledged app.

I managed to get something very close to what I like in a sandbox foundation app, and I'll be incorporating this code into my main project in the next few days:

http://paste2.org/p/1480833

Let me know if you have any comments regarding Cocoa abuse I might've accidentally committed in this code.

kainjow
Jun 20, 2011, 09:37 PM
I suggest reading through Driving OpenGL Rendering Loops (http://developer.apple.com/library/mac/#qa/qa1385/_index.html). Using what Apple suggests will account for about 90% of the "Cocoa abuse" in that code ;)

And capitalized variables is a definite no-no in Cocoa.

Other than that, it's hard to recommend anything without really seeing how you ported the code and structure of your app.

Cromulent
Jun 21, 2011, 05:25 AM
Let me tell you this: as a pro, I'd rather be stabbed than use SDL. Its design is full of hacks (FFS, it #define-s 'main'!), memory allocations at bad times and just plan stupidity.

Redefining main is pretty bad but in general it works and has been used in a number of commercial games. I haven't used the new SDL 1.3 yet, let's hope that is better than 1.2.x.

Starfox
Jun 21, 2011, 05:14 PM
Redefining main is pretty bad but in general it works and has been used in a number of commercial games. I haven't used the new SDL 1.3 yet, let's hope that is better than 1.2.x.

I doubt SDL was used in any grown up commercial game except for SDL_Input in some UE 2.x-powered games on non-Win32 PC platforms. Anyone who had to ship on 360 / PS3 would avoid it like the plague.