Full-screen without OpenGL

George Marlin
Unregistered
 
Post: #1
Most of the sample code I've found for full-screen functionality is for OpenGL. Some non-OpenGL samples are at

http://cocoadevcentral.com/articles/000028.php
http://developer.apple.com/documentation...ementID_40

However I haven't got either to work. More precisely, the fullscreen part works but I cannot blit an image. I am using NSBitmapImageRep's drawAtPoint on the contentView between lockFocus and unlockFocus. However it all works correctly when I use a regular non-fullscreen nib-based window.

I am dirtying the view by calling -setNeedsDisplay:YES and the window by calling -recalculateKeyViewLoop:. I've also tried a few unrelated dirtying functions, and even tried simulating activate/redraw events, all with no effect.

The window creation code follows. Exactly one of MY_FULLSCREEN_TEST, MY_FULLSCREEN_TEST2, MY_NIB_TEST is defined.
Code:
- (void)myCreateWindow
{
#if defined(MY_FULLSCREEN_TEST)
    if( CGDisplayCapture(kCGDirectMainDisplay) != kCGErrorSuccess )
    {
        NSLog(@"Couldn't capture the main display!") ;
        return ;
    }

    int windowLevel = CGShieldingWindowLevel() ;
    NSRect screenRect = [[NSScreen mainScreen] frame] ;
    m_window = [[MyWindow alloc]
                        initWithContentRect:screenRect
                        styleMask:NSBorderlessWindowMask
                        backing:NSBackingStoreBuffered
                        defer:NO
                        screen:[NSScreen mainScreen]] ;
    [m_window makeMainWindow] ;
    [m_window setLevel:windowLevel] ;
#endif // defined(MY_FULLSCREEN_TEST)

#if defined(MY_FULLSCREEN_TEST2)
    // [url]http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/AdvancedDrawing/chapter_9_section_4.html#//apple_ref/doc/uid/TP40003290-CH207-DontLinkElementID_40[/url]

    // Get the screen information.

    NSScreen* mainScreen = [NSScreen mainScreen];
    NSDictionary* screenInfo = [mainScreen deviceDescription];
    NSNumber* screenID = [screenInfo objectForKey:@"NSScreenNumber"];

    // Capture the screen.

    CGDirectDisplayID displayID = (CGDirectDisplayID)[screenID longValue];
    CGDisplayErr err = CGDisplayCapture(displayID);

    if (err == CGDisplayNoErr)
    {
        // Create the full-screen window if it doesn’t already  exist.
        if (!m_window)
        {
            // Create the full-screen window.
            NSRect winRect = [mainScreen frame];
            m_window = [[NSWindow alloc] initWithContentRect:winRect
                    styleMask:NSBorderlessWindowMask
                    backing:NSBackingStoreBuffered
                    defer:NO
                    screen:[NSScreen mainScreen]];

            // Establish the window attributes.
            [m_window setReleasedWhenClosed:NO];
            [m_window setDisplaysWhenScreenProfileChanges:YES];
            [m_window setDelegate:self];

            // Create the content for the window.

            //FullScreenView* theView = [[FullScreenView alloc]
            //                              initWithFrame:winRect];

            NSView* theView = [[NSView alloc]
                                  initWithFrame:winRect];

            [m_window setContentView:theView];
            [theView setNeedsDisplay:YES];
            [theView release];
        }

        // Make the screen window the current document window.
        // Be sure to retain the previous window if you want to  use it again.

        //NSWindowController* winController = [[self windowControllers]
        //                                         objectAtIndex:0];
        //[winController setWindow:m_window];

        // The window has to be above the level of the shield window.

        int32_t     shieldLevel = CGShieldingWindowLevel();
        [m_window setLevel:shieldLevel];

        // Show the window.

        [m_window makeKeyAndOrderFront:self];
    }
#endif // defined(MY_FULLSCREEN_TEST2)

#if defined(MY_NIB_TEST)
    BOOL success = [NSBundle loadNibNamed:@"MainMenu" owner:NSApp] ;
    assert(success) ;
    m_window = [self mainWindow] ;
#endif // defined(MY_NIB_TEST)

    [m_window setBackgroundColor:[NSColor blackColor]] ;
    [m_window makeKeyAndOrderFront:nil] ;
    [[m_window contentView] setNeedsDisplay:YES] ;
}

For the charitable and/or curious, I have a demonstration at

http://www.savefile.com/files/713560

The app attempts to blit a simple gray image (filled with 128,128,128). The commands 'make fullscreen', 'make fullscreen2', 'make windowed' will compile different code for making the window, the latter being the nib-based window which works correctly. For convenience, 'make run' will launch the app. NOTE: the full-screen versions should be remote-debugged, else you won't be able to quit the app (sorry).
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
I remember having trouble with this in one of my fullscreen implementations. Looking at my code, it's pretty similar to yours, so it looks like you're on the right track... My view overrides setNeedsDisplay:, and just draws things immediately while in full screen mode instead of calling [super setNeedsDisplay:]. Might be worth a shot.

You might also need to return YES from -canBecomeKeyWindow in MyWindow, but I'm not 100% sure that's relevant.
Quote this message in a reply
George Marlin
Unregistered
 
Post: #3
ThemsAllTook Wrote:... My view overrides setNeedsDisplay:, and just draws things immediately while in full screen mode instead of calling [super setNeedsDisplay:]. Might be worth a shot.

Thanks for your response. I replaced the NSView with a MyView and did the blit inside -setNeedsDisplay; I also tried calling -display and -drawRect at the end. Still no change.

Quote:You might also need to return YES from -canBecomeKeyWindow in MyWindow, but I'm not 100% sure that's relevant.
Not a bad idea, but I just tried it and it has no effect. (I fixed the 'fullscreen2' version to use MyWindow.)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,006 Jan 13, 2011 01:11 PM
Last Post: SethWillits
  Full screen mouse events Mister T 17 8,279 Jan 4, 2010 02:55 PM
Last Post: MacMan
  Carbon events in windowed/full screen mode. Help needed. Anton Petrov 1 3,535 Dec 18, 2008 05:35 AM
Last Post: DoG
  Full Screen Event Handling kodex 4 4,617 Jun 27, 2008 08:37 PM
Last Post: OneSadCookie
  Full Screen in Cocoa Roger 1 2,866 Aug 9, 2002 07:41 PM
Last Post: furballphat