[英]How to display on dual screens on Mac OS X Lion
I want my app to be displayed on both laptop screen and an external screen with two separated NSWindow, I can't find any document about how to implement it. 我希望将我的应用程序同时显示在笔记本电脑屏幕和带有两个单独的NSWindow的外部屏幕上,但找不到有关如何实现它的任何文档。 Any hint? 有什么提示吗?
Thanks 谢谢
The OS X OpenGL Programming Guide shows the old way of making a full-screen window: 《 OS X OpenGL编程指南》展示了制作全屏窗口的旧方法:
Create a screen-sized window on the display you want to take over: 在要接管的显示器上创建一个屏幕大小的窗口:
NSRect mainDisplayRect = [[NSScreen mainScreen] frame]; NSWindow *fullScreenWindow = [[NSWindow alloc] initWithContentRect: mainDisplayRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
Set the window level to be above the menu bar.: 将窗口级别设置为在菜单栏上方。
[fullScreenWindow setLevel:NSMainMenuWindowLevel+1];
Perform any other window configuration you desire: 执行所需的任何其他窗口配置:
[fullScreenWindow setOpaque:YES]; [fullScreenWindow setHidesOnDeactivate:YES];
Create a view with a double-buffered OpenGL context and attach it to the window: 使用双缓冲OpenGL上下文创建视图,并将其附加到窗口:
NSOpenGLPixelFormatAttribute attrs[] = { NSOpenGLPFADoubleBuffer, 0 }; NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; NSRect viewRect = NSMakeRect(0.0, 0.0, mainDisplayRect.size.width, mainDisplayRect.size.height); MyOpenGLView *fullScreenView = [[MyOpenGLView alloc] initWithFrame:viewRect pixelFormat: pixelFormat]; [fullScreenWindow setContentView: fullScreenView];
Show the window: 显示窗口:
[fullScreenWindow makeKeyAndOrderFront:self];
You can use this method to create windows on each screen that you want to draw to. 您可以使用此方法在要绘制到的每个屏幕上创建窗口。 If you use this to create a window on only one screen, the other screen will continue to function normally, instead of being blacked out or covered in a stupid linen texture. 如果使用此方法仅在一个屏幕上创建一个窗口,则另一个屏幕将继续正常运行,而不是被涂黑或覆盖在愚蠢的亚麻质地中。 Depending on your use, you may not want to setHidesOnDeactivate
. 根据您的用途,您可能不希望setHidesOnDeactivate
。
There are also lower-level APIs to take control of a screen completely and prevent the OS or any other application from drawing to the screen, but their use is seldom justified. 还有一些较低级别的API可以完全控制屏幕,并防止OS或任何其他应用程序绘制到屏幕上,但是使用它们的理由很少。
EDIT: If you want to have one GL context with the render spanning multiple screens, you need to create a single window with a NSRect
that spans all the screens. 编辑:如果要使一个GL上下文具有跨多个屏幕的渲染,则需要创建一个NSRect
跨所有屏幕的单个窗口。 If the screen resolutions aren't matched, this may result in part of your window not being visible, and low-end graphics chips may have some problems. 如果屏幕分辨率不匹配,则可能导致部分窗口不可见,并且低端图形芯片可能会出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.