且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Mac OS X Lion的双屏幕上显示

更新时间:2023-11-14 12:40:40

The OS X OpenGL Programming Guide shows the old way of making a full-screen window:

  1. 在您要接管的显示器上创建一个屏幕大小的窗口:

  1. 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];
    

  • 使用双缓冲OpenGL上下文创建视图并将其附加到窗口:

  • Create a view with a double-buffered OpenGL context and attach it to the window:

    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];
    

  • 您可以使用此方法在要绘制到的每个屏幕上创建窗口.如果使用此方法仅在一个屏幕上创建窗口,则另一个屏幕将继续正常运行,而不是被涂黑或覆盖在愚蠢的亚麻质地中.根据您的用途,您可能不想setHidesOnDeactivate.

    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.

    还有一些较低级别的API可以完全控制屏幕并阻止OS或任何其他应用程序绘制到屏幕上,但是很少有理由使用它们.

    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.

    如果要使一个GL上下文具有跨多个屏幕的渲染,则需要创建一个具有NSRect且跨所有屏幕的单个窗口.如果屏幕分辨率不匹配,则可能会导致部分窗口不可见,并且低端图形芯片可能会出现问题.

    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. 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.