I am trying out OpenGL 3.2 using a Cocoa window and an NSOpenGLView. However I can't get the NSOpenGLView to draw a red color. I just get a white window. Here is my code (inside subclass of NSOpenGLView):
-(void)awakeFromNib{
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 24,
// Must specify the 3.2 Core Profile to use OpenGL 3.2
NSOpenGLPFAOpenGLProfile,
NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease];
if (!pf)
{
NSLog(@"No OpenGL pixel format");
}
NSOpenGLContext *context = [[[NSOpenGLContext alloc]initWithFormat:pf shareContext:nil]autorelease];
[self setPixelFormat:pf];
[self setOpenGLContext:context];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
The code should simply clear the view to red. No errors or warnings -- just a white window.
I needed to swap the buffers using glSwapAPPLE() after my call to glClear()
I read somewhere that NSOpenGLViews don't need to be swapped because it is done automatically. After my experience I can say that is completely untrue.