I'm having trouble to get NSOpenGLContext working. I have a static object (3D engine) that handle all the opengl stuff, resources , vbos etc..
For the cocoa version, i create a NSOpenGLContext like this :
- (BOOL) CreateContext
{
[NSOpenGLContext clearCurrentContext];
NSOpenGLPixelFormatAttribute attributes [] =
{
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated, // If present, this attribute indicates that only hardware-accelerated renderers are considered.
NSOpenGLPFAPixelBuffer, // If present, this attribute indicates that rendering to a pixel buffer is enabled.
NSOpenGLPFAColorSize, 32,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
(NSOpenGLPixelFormatAttribute)nil
};
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
NSOpenGLContext* pContext = [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext:nil];
if (pContext)
{
[pContext makeCurrentContext];
m_pOGLContext = pContext;
// Vertical Sync
GLint vblSynch = 0; // disable vsync
[pContext setValues:&vblSynch forParameter:NSOpenGLCPSwapInterval];
glFrontFace(GL_CW);
// Set the clear Color
glClearColor(0, 0, 0, 0);
[pixelFormat release];
return true;
}
[pixelFormat release];
return false;
}
After the engine initialization, I create an NSView. After the NSView creation, in the prepareOpenGL func, i just set the NSOpenGLContext member to the current NSOpenGLContext from the engine :
- (void) prepareOpenGL
{
m_pOGLContext = [NSOpenGLContext currentContext];
return;
}
Then, in the function lockFocus of the NSView i set the view for the context :
- (void)lockFocus
{
[super lockFocus];
if ([m_pOGLContext view] != self)
{
[m_pOGLContext setView:self];
}
[m_pOGLContext makeCurrentContext];
}
Now, when drawing i can't get resources to be drawn, i just have a lot of buffer artifacts.
I tried to create a second Context for the NSView, with the sharing option, but i have the same result.