gpt4 book ai didi

macos - 如何以编程方式以特定分辨率渲染全屏 openGL?

转载 作者:行者123 更新时间:2023-12-03 17:31:35 27 4
gpt4 key购买 nike

我正在开发一个 OSX/Cocoa 图形应用程序(出于性能原因),当用户选择“全屏”模式时,我希望以 640x480 渲染。就其值(value)而言,内容是使用 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];

最佳答案

使用附加了所需目标分辨率纹理的 FBO,并以所述分辨率渲染到该 FBO/纹理。然后切换到主帧缓冲区并使用之前渲染的纹理绘制全屏四边形。使用您最喜欢的任何放大滤镜。如果您想发挥更大的作用,您可以在片段着色器中实现 Lancosz/sinc 插值器来升级中间纹理。

关于macos - 如何以编程方式以特定分辨率渲染全屏 openGL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18468030/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com