Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up and using OpenGL 3.0+ with Mac OSX Lion(10.7)

I am trying to set up an OpenGL 3.0+ context within XCode 4.

As you can see talking about shaders here at the developer website the example it uses is OpenGL 2.0. In Appendix B it does talk about updating for 3.2 but just shows you function name changes and what only applies to the core, yet there is no example of actually setting up an OpenGL context. This has changed greatly since the fixed function pipeline being that you can no longer do things like glMatrixMode(...).. etc etc...i.e. opengl states are no longer.

If anyone can point me to a link somewhere on the web of setting up an OpenGL 3.0+ context on Mac OSX 10.7 using XCode 4 it would be appreciated.

like image 553
cspam Avatar asked Jan 16 '12 01:01

cspam


1 Answers

There is some example code here for setting up an 3.2 context inside an NSOpenGLView.

Or using Core GL,

CGLPixelFormatAttribute attribs[13] = {
    kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, // This sets the context to 3.2
    kCGLPFAColorSize,     (CGLPixelFormatAttribute)24,
    kCGLPFAAlphaSize,     (CGLPixelFormatAttribute)8,
    kCGLPFAAccelerated,
    kCGLPFADoubleBuffer,
    kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1,
    kCGLPFASamples,       (CGLPixelFormatAttribute)4,
    (CGLPixelFormatAttribute)0
};

CGLPixelFormatObj pix;
GLint npix;
CGLChoosePixelFormat(attribs, &pix, &npix);

CGLContextObj ctx;
CGLCreateContext(pix, 0, &ctx);

CGLSetCurrentContext(ctx);
CGLLockContext(ctx);

In either case you have to do it manually(not through InterfaceBuilder) because it's opt-in.

like image 168
user1139069 Avatar answered Oct 20 '22 10:10

user1139069