I'm trying to create an OpenGL application using Cocoa API, and by now everything works fine, except for one thing. When the main window is resized the GL context seems not be updated properly.
Here's is the code used to setup window and render context.
Main window:
m_window = [[NSWindow alloc] initWithContentRect:window_rect
styleMask:( NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSTitledWindowMask | NSResizableWindowMask )
backing:NSBackingStoreBuffered defer:YES];
window_title = [NSString stringWithCString:m_window_title->c_str()
encoding:NSUTF8StringEncoding];
window_color = [NSColor colorWithCalibratedRed:m_window_color->getRed()
green:m_window_color->getGreen()
blue:m_window_color->getBlue()
alpha:m_window_color->getAlpha()];
if ( m_centered )
{
[m_window center];
}
[m_window setTitle:window_title];
[m_window setBackgroundColor:window_color];
[m_window setOneShot:YES];
[m_window setOpaque:YES];
[m_window setDelegate:window_delegate];
[m_window setAcceptsMouseMovedEvents:YES];
OpenGL view:
NSOpenGLPixelFormatAttribute attrs[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFAWindow, NULL};
pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
m_view = [[NSOpenGLView alloc] initWithFrame:[m_window contentRectForFrameRect:[m_window frame]]
pixelFormat:pixel_format];
[pixel_format release];
GLint dim[2] = {GB_DEF_WINDOW_WIDTH, GB_DEF_WINDOW_HEIGHT};
CGLContextObj ctx = (CGLContextObj) [[m_view openGLContext] CGLContextObj];
CGLSetParameter(ctx, kCGLCPSurfaceBackingSize, dim);
CGLEnable (ctx, kCGLCESurfaceBackingSize);
[[m_view openGLContext] makeCurrentContext];
[m_window setContentView:m_view];
This should work, however when the window is resized and after updating OpenGL view and the viewport, the back buffer content seems not to be rescaled correctly. What's wrong with that?
Thanks for your replies.