title: NSOpenGLView - View not refreshing until i move the window
body: <p>I'm really tearing my head out on this one!</p>
  
  <p>I'm subclassing NSOpenGLView to do some animations on the view.
  When i say animations, i mean that am moving some images from left to right of the view and so on.</p>
  
  <p>This is what i do</p>
  
  <p>a) Initialise the OpenGL system
  Code:</p>
  
  <pre><code>- (id)initWithFrame:(NSRect)frame
  {
      NSOpenGLPixelFormatAttribute attrs[] = {
  
      NSOpenGLPFANoRecovery, // Enable automatic use of OpenGL "share" contexts.
      NSOpenGLPFAColorSize, 24,
      NSOpenGLPFAAlphaSize, 8,
      NSOpenGLPFADepthSize, 16,
      NSOpenGLPFADoubleBuffer,
      NSOpenGLPFAAccelerated,
      0
  };
  // Create our pixel format.
  NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc]        initWithAttributes:attrs];
  self = [super initWithFrame:frame pixelFormat:pixelFormat];
  
  
  return self;
  }
  
  // Synchronize buffer swaps with vertical refresh rate
  - (void)prepareOpenGL
  {
      GLint swapInt = 1;
     [[self openGLContext] setValues:&amp;swapInt forParameter:NSOpenGLCPSwapInterval];
  }
  </code></pre>
  
  <p>b) Setup the Timers on Start</p>
  
  <pre><code>   Code:
     // Put our timer in -awakeFromNib, so it can start up right from the beginning
    -(void)awakeFromNib
    {
     if( gameTimer != nil )
       [gameTimer invalidate];
  
     gameTimer = [NSTimer timerWithTimeInterval:0.02   //time interval
                                      target:self
                                    selector:@selector(timerFired:)
                                    userInfo:nil
                                     repeats:YES];
  
     [[NSRunLoop currentRunLoop] addTimer:gameTimer
                               forMode:NSDefaultRunLoopMode];
     [[NSRunLoop currentRunLoop] addTimer:gameTimer
                               forMode:NSEventTrackingRunLoopMode]; //Ensure timer fires   during resize*/
     }
  
  
     // Timer callback method
    - (void)timerFired:(id)sender
   {
      //The timer fires this method every second
      currentTime ++;
  
      // All we do here is tell the display it needs a refresh
     [self setNeedsDisplay:YES];
   }
  </code></pre>
  
  <p>c) Animate my stuff in drawRect</p>
  
  <pre><code> Code:
   - (void)drawRect:(NSRect)rect
  {
     [self animateFrame:rect];
  
    // the correct way to do double buffering is this:
    [[self openGLContext] flushBuffer];
  }
  </code></pre>
  
  <p>d) The animateFrame method just draws images in various rectangle positions</p>
  
  <pre><code> Code:
   [curImage drawInRect:targetRect
              fromRect:sourceRect
             operation:NSCompositeSourceOver
              fraction:1.0f];
  </code></pre>
  
  <hr>
  
  <p>So here is the problem</p>
  
  <p>When i start the app - i can see that time timer is being fired, drawRect is being invoked and the images are being drawn.</p>
  
  <p>However i can only see the animation of the images, when i drag the window and move the window..
  When the window is still the images just stay frozen.
  When i move the window - i see the images are moving... 
  Or even if i get the window out of focus and back in focus - i can see the image changes positions...</p>
  
  <p>I feel that the OpenGLView is not painting itself when static...
  I dont know what else is to be done...</p>
  
  <p>Do i have to invoke - [[self openGLContext] flushBuffer]; 
  How do i ensure the View is getting painted always?</p>
  
  <p>Can someone shed light on what is going on here or what have i missed?</p>
  
  <p>Appreciate some help.
  Thanks in advance!
  KamyFC</p>