title: CAOpenGLLayer has clipped image
body: <p>I am struggling with CAOpenGLLayer.</p>
  
  <p>My problem is, when I resize window smaller than initial size, internal image is clipped (top or right part is gone). I have tried to adjust glViewport() or glOrtho(), but it does not work. Please give me advise.</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  #import "MyOpenGLLayer.h"
  
  @interface CALayerTestAppDelegate : NSObject &lt;NSApplicationDelegate&gt; {
      NSWindow *window;
  }
  @property (assign) IBOutlet NSWindow *window;
  @end
  
  @implementation CALayerTestAppDelegate
  @synthesize window;
  - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  {
      [[window contentView] setWantsLayer:YES];
      CALayer *contentLayer = [[window contentView] layer];
      MyOpenGLLayer *layer = [MyOpenGLLayer layer];
      [contentLayer addSublayer:layer];
  
      layer.contentsGravity = kCAGravityCenter;
      layer.bounds = contentLayer.bounds;
      layer.frame = contentLayer.frame;
      layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
      layer.asynchronous = YES;
  }
  @end
  </code></pre>
  
  <p>With following CAOpenGLLayer subclass:</p>
  
  <pre><code>@interface MyOpenGLLayer : CAOpenGLLayer 
  @end
  
  @implementation MyOpenGLLayer
  - (void)drawInCGLContext:(CGLContextObj)glContext 
           pixelFormat:(CGLPixelFormatObj)pixelFormat 
          forLayerTime:(CFTimeInterval)timeInterval 
           displayTime:(const CVTimeStamp *)timeStamp {
  NSRect bounds = NSRectFromCGRect([self bounds]);
  GLfloat minX, minY, maxX, maxY;        
  minX = NSMinX(bounds);
  minY = NSMinY(bounds);
  maxX = NSMaxX(bounds);
  maxY = NSMaxY(bounds);
  
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  
  glViewport(minX, minY, maxX, maxY);
  glOrtho(minX, maxX, minY, maxY, -1.0, 1.0);
  
  glClearColor(0.0, 0.5, 0.5, 1.0);         
  glClear(GL_COLOR_BUFFER_BIT);
  
  const size_t unit = 40;
  for (int x = 0; x&lt;[self bounds].size.width; x+=unit) 
      for (int y = 0; y&lt;[self bounds].size.height; y+=unit)
          if ((x + y)/unit &amp; 1) 
              glRectd(x, y, x+unit, y+unit);
  glFlush();
  
  [super drawInCGLContext:glContext pixelFormat:pixelFormat 
             forLayerTime:timeInterval displayTime:timeStamp];
  }
  @end
  </code></pre>