I've been searching for this answer for so long and cannot find it (OpenGL and C++)

Discussion in 'Mac Programming' started by chrono1081, Aug 2, 2011.

  1. chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #1
    Hi guys,

    For the past week and a half I've been searching for a way to use OpenGL on the Mac without using GLUT or coding in Objective-C, but I can't find anywhere that shows the native window drawing code in anything other than Objective-C.

    Here's my question, if I want to program in C++ and OpenGL without GLUT or SDL (since apparently SDL doesn't support newer OGL implementations according to sources I've found), what would be the steps to take? Just to draw a window? If anyone had a code snipped that would be super amazing :)


    Right now I'm in Apples documentation and its obviously in Objective-C, do I perhaps need to draw the window in Objective-C then do my coding in C++? I've never mixed languages before (except for C and C++) so I'm not sure how well that works.

    I'm just having the hardest time learning OpenGL :/ (I'm familiar with it, but no expert and sources for Mac are scarce).

    Also since I know others are in this same boat if I ever figure this out I'll turn my abandoned game dev blog into a tutorial site for us OGL beginners :)
     
  2. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #2
    Mixing Objective-C and C++ is really not a big deal. In one of my apps, I use C++ for my core drawing stuff (ultimately using Quartz). It would look something like this:

    Code:
    - (void)drawRect:(NSRect)rect
    {
        NSGraphicsContext *nsctx = [NSGraphicsContext currentContext];
        CGContextRef context = (CGContextRef)[nsctx graphicsPort];
        m_yourCPlusPlusModel->Draw(dcontext, (CGRect*)&rect);
    }
    
    Note that the last line is a real C++ method call. In the CPlusPlusModel, I don't use any Objective-C. I assume you could use OpenGL in the same way (although I've never tried it).
     

Share This Page