我正在开发一个OSX / Cocoa图形应用程序(出于性能原因)我希望在用户选择“全屏”模式时以640x480渲染。对于它的价值,内容是一个使用openGL绘制的自定义NSView。
我理解,不是实际更改用户的分辨率,而是更改后备缓冲区(如另一个SO问题所述:Programmatically change resolution OS X)。
根据这个建议,我最终得到以下两种方法(见下文),以在全屏和窗口之间切换。麻烦的是,当我全屏显示时,内容确实以640x480渲染但未缩放(IE看起来好像我们保持在窗口的分辨率并“缩放”到渲染的640x480角落。)
我可能在这里遗漏了一些明显的东西 - 我想我可以根据实际的屏幕分辨率将渲染转换为“居中”它,但这看起来过于复杂?
- (void)goFullscreen{
// Bounce if we're already fullscreen
if(_isFullscreen){return;}
// Save original size and position
NSRect frame = [self.window.contentView frame];
original_size = frame.size;
original_position = frame.origin;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO],NSFullScreenModeAllScreens,
nil];
// In lieu of changing resolution, we set the backbuffer to 640x480
GLint dim[2] = {640, 480};
CGLSetParameter([[self openGLContext] CGLContextObj], kCGLCPSurfaceBackingSize, dim);
CGLEnable ([[self openGLContext] CGLContextObj], kCGLCESurfaceBackingSize);
// Go fullscreen!
[self enterFullScreenMode:[NSScreen mainScreen] withOptions:options];
_isFullscreen=true;
}
- (void)goWindowed{
// Bounce if we're already windowed
if(!_isFullscreen){return;}
// Reset backbuffer
GLint dim[2] = {original_size.width, original_size.height};
CGLSetParameter([[self openGLContext] CGLContextObj], kCGLCPSurfaceBackingSize, dim);
CGLEnable ([[self openGLContext] CGLContextObj], kCGLCESurfaceBackingSize);
// Go windowed!
[self exitFullScreenModeWithOptions:nil];
[self.window makeFirstResponder:self];
_isFullscreen=false;
}
这里现在做类似于datenwolf的建议,但不使用openGL(对于非gl内容很有用)。
// Render into a specific size
renderDimensions = NSMakeSize(640, 480);
NSImage *drawIntoImage = [[NSImage alloc] initWithSize:renderDimensions];
[drawIntoImage lockFocus];
[self drawViewOfSize:renderDimensions];
[drawIntoImage unlockFocus];
[self syphonSendImage:drawIntoImage];
// Resize to fit preview area and draw
NSSize newSize = NSMakeSize(self.frame.size.width, self.frame.size.height);
[drawIntoImage setSize: newSize];
[[NSColor blackColor] set];
[self lockFocus];
[NSBezierPath fillRect:self.frame];
[drawIntoImage drawAtPoint:NSZeroPoint fromRect:self.frame operation:NSCompositeCopy fraction:1];
[self unlockFocus];
答案 0 :(得分:4)
使用附加了所需目标分辨率纹理的FBO,并以所述分辨率渲染到该FBO /纹理。然后切换到主帧缓冲区并使用之前渲染的纹理绘制全屏四边形。使用您最喜欢的放大滤镜。如果你想带出大枪,你可以在片段着色器中实现一个Lancosz / sinc插值器来升级中间纹理。