objective-c - 具有自定义分辨率的 OSX 全屏(信息亭)应用程序

标签 objective-c macos cocoa metal

我有一个 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 的边界。默认情况下,CAMetalLayerdrawableSize 等于其边界乘以其内容比例。但是,您可以通过显式设置图层的 drawableSize 将其设置为您想要的任何大小。

关于objective-c - 具有自定义分辨率的 OSX 全屏(信息亭)应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35142525/

相关文章:

objective-c - 基于 Cocoa 文档的应用程序在 Command W 上不执行任何操作

ios - 从今天的日期和带有时间的字符串构造一个 NSDate

iphone 应用程序 webview 链接操作

macos - Mac OS X : what causes the spinning beach ball?

node.js - 浏览器同步 : Command not found after installing browser-sync

objective-c - 查找类是否符合给定键的键值

swift - 在 NSView 中编写

Objective-C 有人可以解释一下如何以编程方式显示 View 吗

iphone - 多个服务器使用相同的 SSL 证书连接到 APNS

macos - NSButton mouseDown mouseUp 在启用时表现不同