Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
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 🙂
 
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).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.