Full Screen Switching

Member
Posts: 254
Joined: 2005.10
Post: #1
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];
}
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #2
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Member
Posts: 254
Joined: 2005.10
Post: #4
Well I finally fixed it by adding
Code:
if(isFullScreen) [fullScreenContext setFullScreen];
to the drawRect method.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  switching screen resolution NelsonMandella 3 3,558 Apr 25, 2010 01:33 PM
Last Post: SethWillits
  Full Screen OpenGL Crashes Blacktiger 13 8,054 Feb 19, 2009 02:39 PM
Last Post: backslash
  OpenGL full screen mode leaves garbage on screen when exiting app Malarkey 5 5,420 Nov 19, 2008 12:51 PM
Last Post: Malarkey
  Changing resolution while already in full-screen mode? Malarkey 1 2,729 Jun 10, 2008 07:49 PM
Last Post: AnotherJake
  Dealing with Battery Low Warning During Full Screen AnotherJake 8 5,840 Feb 8, 2008 12:26 PM
Last Post: OneSadCookie