NSGL full screen problems

Moderator
Posts: 608
Joined: 2002.04
Post: #1
Can anyone figure out why this only gives me a black screen when I attempt to go into full screen?

Code:
- (id)initWithFrame:(NSRect)frameRect color:(int)color depth:(int)depth
{
    NSOpenGLPixelFormatAttribute attr[] =
    {
        NSOpenGLPFAWindow,
        NSOpenGLPFASingleRenderer,
        NSOpenGLPFANoRecovery,
        NSOpenGLPFAScreenMask,
        (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(kCGDirectMainD​isplay),
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAAccelerated,
        NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)color,
        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depth,
        (NSOpenGLPixelFormatAttribute)0
    };

    NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
    if(pixelFormat == nil)
    {
        NSLog(@"Windowed pixel format is null");
        return nil;
    }
    [pixelFormat autorelease];
    
    attr[0] = NSOpenGLPFAFullScreen;
    NSOpenGLPixelFormat *fullScreenPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
    if(fullScreenPixelFormat == nil)
    {
        NSLog(@"Full screen pixel format is null");
        return nil;
    }
    [fullScreenPixelFormat autorelease];
    
    self = [super initWithFrame:frameRect pixelFormat:pixelFormat];
    if(self == nil)
    {
        NSLog(@"View is null");
        return nil;
    }
    
    fullScreenContext = [[NSOpenGLContext alloc] initWithFormat:fullScreenPixelFormat
                                                   shareContext:[self openGLContext]];
    if(fullScreenContext == nil)
    {
        NSLog(@"Full screen context is null");
    
        [self dealloc];
        return nil;
    }
    
    isFullScreen = NO;
    
    [self initApp];
    [self initOpenGL];
    [self reshape];

    return self;
}

- (id)initWithFrame:(NSRect)frameRect
{
    self = [self initWithFrame:frameRect
                         color:DEFAULT_COLOR
                         depth:DEFAULT_DEPTH];
    
    if(self == nil)
    {
        NSLog(@"View is null");
        return nil;
    }
    
    return self;
}

- (void)initApp
{
    [NSTimer scheduledTimerWithTimeInterval:0.001
                                     target:self
                                   selector:@selector(drawRect:)
                                   userInfo:nil
                                    repeats:YES];
                                    
    [[self window] setDelegate:self];
}

- (IBAction)toggleFullScreen:(id)sender
{
    if(isFullScreen)
    {
        [fullScreenContext clearDrawable];
        [[self openGLContext] makeCurrentContext];
        
        CGReleaseAllDisplays();
        
        isFullScreen = NO;
    }
    
    else
    {
        CGCaptureAllDisplays();
        
        [fullScreenContext setFullScreen];
        [fullScreenContext makeCurrentContext];
        
        isFullScreen = YES;
    }
}
drawRect: is implemented by this class' subclass. It draws fine in windowed mode, but draws nothing in full screen. I've already determined through lots of NSLogs that the subclass' drawRect: gets called in full screen. I get no error messages on the console.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
Does color match the depth of the current display mode?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #3
Wow, I completely forgot I posted this...

I ended up figuring it out, and I believe the difference in color depth was part of the problem. It also had something to do with timers being goofy...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Full Screen OpenGL Crashes Blacktiger 13 7,825 Feb 19, 2009 02:39 PM
Last Post: backslash
  OpenGL full screen mode leaves garbage on screen when exiting app Malarkey 5 5,302 Nov 19, 2008 12:51 PM
Last Post: Malarkey
  Changing resolution while already in full-screen mode? Malarkey 1 2,667 Jun 10, 2008 07:49 PM
Last Post: AnotherJake
  Full Screen Switching Blacktiger 3 3,622 Feb 9, 2008 03:05 PM
Last Post: Blacktiger
  Dealing with Battery Low Warning During Full Screen AnotherJake 8 5,777 Feb 8, 2008 12:26 PM
Last Post: OneSadCookie