title: NSOpenGLView and CVDisplayLink, no default frame buffer
body: <p>I have an NSOpenGLView and OpenGL code that works with an NSTimer running in the main loop (calling setNeedsDisplay and drawRect). I would like to use a CVDisplayLink, so I can get a better frame-rate without overdriving the timer. I copied most of the code from apple's OSXGLEssentials example. The display link starts and the callback runs, but nothing is actually draw on screen. glGetError returns GL_INVALID_FRAMEBUFFER_OPERATION.</p>
  
  <p>glCheckFramebufferStatus returns GL_FRAMEBUFFER_UNDEFINED for GL_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER. </p>
  
  <p>Info from the documentation:</p>
  
  <blockquote>
    <p>GL_FRAMEBUFFER_UNDEFINED is returned if target is the default
    framebuffer, but the default framebuffer does not exist.</p>
  </blockquote>
  
  <p>Here are the relevant bits of code:</p>
  
  <pre><code>- (void)awakeFromNib {
  
    NSOpenGLPixelFormatAttribute attributes[] = {
      NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,   // Core Profile !
      NSOpenGLPFADoubleBuffer,
      NSOpenGLPFAAccelerated,
      NSOpenGLPFAColorSize, 24,
      NSOpenGLPFAAlphaSize, 8,
      NSOpenGLPFAAllowOfflineRenderers,
      0
    };
  
    NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:format shareContext: nil];
    // [context setView: self];
    [self setPixelFormat: format];
    [self setOpenGLContext: context];
  
  }
  
  
  - (void)prepareOpenGL {
  
    [super prepareOpenGL];
  
    NSOpenGLContext* context = [self openGLContext];
    [context makeCurrentContext];
  
    // Synchronize buffer swaps with vertical refresh rate
    GLint swapInt = 1;
    [context setValues:&amp;swapInt forParameter:NSOpenGLCPSwapInterval];
  
    MyDisplay_setup();
    MyDisplay_initScene(_bounds.size.width, _bounds.size.height);
  
    CVDisplayLinkCreateWithActiveCGDisplays(&amp;displayLink);
    CVDisplayLinkSetOutputCallback(displayLink, &amp;displayLinkCallback, (__bridge void *)self);
    CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
    CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, [context CGLContextObj], cglPixelFormat);
    CVDisplayLinkStart(displayLink);
  
  }
  
  
  static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime,
  CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) {
  
    @autoreleasepool {
      [(__bridge MyView*)displayLinkContext redraw];
    }
    return kCVReturnSuccess;
  
  }
  
  
  - (void)redraw {
  
    NSOpenGLContext* context = [self openGLContext];
    [context makeCurrentContext];
    CGLLockContext([context CGLContextObj]);
    MyDisplay_drawScene();
    CGLFlushDrawable([context CGLContextObj]);
    CGLUnlockContext([context CGLContextObj]);
  
  }
  </code></pre>