Programmatically creating an OpenGL window

Discussion in 'Mac Programming' started by Starfox, Jun 20, 2011.

  1. macrumors regular

    Joined:
    Apr 7, 2011
    #1
    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.
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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.
     
  3. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    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.
     
  4. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #4
    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.
     
  5. thread starter macrumors regular

    Joined:
    Apr 7, 2011
    #5
    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.
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    I suggest reading through Driving OpenGL Rendering Loops. 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.
     
  7. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    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.
     
  8. thread starter macrumors regular

    Joined:
    Apr 7, 2011
    #8
    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.
     

Share This Page