iDevGames Forums
Full Screen Switching - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Full Screen Switching (/thread-2779.html)



Full Screen Switching - Blacktiger - Feb 9, 2008 12:45 PM

I'm working on an NSOpenGLView subclass to control full screen switching and so far it's looking good except when I am in full screen mode, I just have a black screen! Can anyone see why?

Code:
- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self)
    {
    // Create the windowed and full screen contexts.
    NSOpenGLPixelFormatAttribute windowedAttributes[] =
    {
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAAccelerated,
        NSOpenGLPFADepthSize, 24,
        NSOpenGLPFAStencilSize, 8,
        NSOpenGLPFANoRecovery,
        NSOpenGLPFASingleRenderer,
        NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
        0
    };
    NSOpenGLPixelFormat* windowedPF = [[[NSOpenGLPixelFormat alloc] initWithAttributes: windowedAttributes] autorelease];
    windowedContext = [[NSOpenGLContext alloc] initWithFormat: windowedPF shareContext: nil];
    
    NSOpenGLPixelFormatAttribute fullScreenAttributes[] =
    {
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAAccelerated,
        NSOpenGLPFADepthSize, 24,
        NSOpenGLPFAStencilSize, 8,
        NSOpenGLPFANoRecovery,
        NSOpenGLPFASingleRenderer,
        NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
        NSOpenGLPFAFullScreen,
        0
    };
    NSOpenGLPixelFormat* fullScreenPF = [[[NSOpenGLPixelFormat alloc] initWithAttributes: fullScreenAttributes] autorelease];
    fullScreenContext = [[NSOpenGLContext alloc] initWithFormat: fullScreenPF shareContext: windowedContext];
    }
    
    [self setOpenGLContext:windowedContext];
    
    return self;
}

- (void)drawRect:(NSRect)rect
{
    glClearColor(0.2f, 0.25f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    [[self openGLContext] flushBuffer];
}

- (IBAction) toggleFullScreen:(id)sender
{
    [NSOpenGLContext clearCurrentContext];

    if(isFullScreen)
    {
        isFullScreen = NO;
        [fullScreenContext clearDrawable];
        
        CGReleaseAllDisplays();
        
        [self setOpenGLContext:windowedContext];
        [[self window] makeKeyAndOrderFront:self];
        
        [NSCursor unhide];
        [NSMenu setMenuBarVisible:YES];
    }
    else
    {
        isFullScreen = YES;
        [windowedContext clearDrawable];
        
        CGCaptureAllDisplays();
        
        [fullScreenContext setFullScreen];
        [self setOpenGLContext:fullScreenContext];
        
        [NSCursor hide];
        [NSMenu setMenuBarVisible:NO];
    }
    [self display];
}



Full Screen Switching - Cochrane - Feb 9, 2008 02:20 PM

Where do you set glViewport? State like this isn't shared by contexts, only data like textures can be shared, so you'll have to call glViewport and others again after toggling full screen.

I'm not sure if that's the problem, though. Better wait for an expert. Quick question: When you exit full screen again, does everything work as expected?


Full Screen Switching - OneSadCookie - Feb 9, 2008 02:34 PM

http://onesadcookie.com/svn/AbandonedExperiments/CreatingMacGames/
http://onesadcookie.com/svn/GameShell


Full Screen Switching - Blacktiger - Feb 9, 2008 03:05 PM

Well I finally fixed it by adding
Code:
if(isFullScreen) [fullScreenContext setFullScreen];
to the drawRect method.