我有一个 OS X Metal 应用程序,我想以非 native 分辨率全屏运行,例如我的原始分辨率是 1920x1080,我想以 1024x768 全屏渲染应用程序。 (我不认为使用 Metal 来绘制东西会影响这个问题,除非我无法使用 OpenGL 特定的 NSView
函数。)
我的渲染器使用硬编码大小为 1024x768 的后台缓冲区。
当我使用 bounds = 1024x768
创建窗口时我得到一个全屏窗口,但我的内容是居中绘制的,并且不会拉伸(stretch)以填充整个屏幕。
当我使用 bounds = 1920x1080
创建窗口时我得到一个全屏窗口,但我的内容绘制在左上角并且缩放不正确(因为两种分辨率之间的比例不匹配)。
使用[NSView - enterFullScreenMode:withOptions:]
产生了相同的结果。设置[NSView autoresizingMask]
也没有改变任何东西。
理想情况下,我希望窗口的大小与屏幕的大小相同,并且将低分辨率后台缓冲区拉伸(stretch)以填充整个窗口。我缺少什么才能让我做到这一点?
相关应用初始化来 self 的NSResponder <NSApplicationDelegate>
:
// Create the window
self.Window = [NSWindow alloc];
[self.Window initWithContentRect:bounds
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];
// Create the view
self.View = [NSView alloc];
[self.View initWithFrame:bounds];
[self.View setWantsLayer:YES]; // The generated layer is CAMetalLayer
// Associate the view with the window
[self.Window setContentView:self.View];
// Misc
[self.Window makeKeyAndOrderFront:self.Window];
[self.Window setAcceptsMouseMovedEvents:YES];
[self.Window setHidesOnDeactivate:YES];
// Fullscreen
[self.Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self.Window toggleFullScreen:nil];
[self.Window makeFirstResponder:self.View];
谢谢。
最佳答案
支持 View 的图层的框架必须等于该 View 的边界。默认情况下,CAMetalLayer
的 drawableSize
等于其边界乘以其内容比例。但是,您可以通过显式设置图层的 drawableSize
将其设置为您想要的任何大小。
关于objective-c - 具有自定义分辨率的 OSX 全屏(信息亭)应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35142525/