iDevGames Forums
Fullscreen Frustrations - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Fullscreen Frustrations (/thread-1781.html)



Fullscreen Frustrations - robotseatpeople - Feb 9, 2009 02:52 PM

I'm having difficulties getting fullscreen mode to work right. At the moment it's set up as a windowed/fullscreen deal. Whenever I enter fullscreen whatever was drawn in the window disappears.

Here's my code:

Code:
@implementation View
- (void) makeFullScreen {
    NSOpenGLPixelFormatAttribute attributes[] = {
        NSOpenGLPFAFullScreen,
        NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
        NSOpenGLPFAColorSize, 24,
        NSOpenGLPFADepthSize, 16,
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAAccelerated,
        0
    };
    
    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: attributes];
    
    NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:NULL];
    
    [pixelFormat release];
    
    pixelFormat = nil;
    
    CGCaptureAllDisplays();
    
    [context setFullScreen];
    [context makeCurrentContext];
}

- (BOOL) acceptsFirstResponder {
    return YES;
}

- (void) drawRect: (NSRect) bounds {
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    {
        glVertex3f(  0.0,  0.6, 0.0);
        glVertex3f( -0.2, -0.3, 0.0);
        glVertex3f(  0.2, -0.3 ,0.0);
    }
    glEnd();
    glFlush();
}

- (void) keyDown: (NSEvent*) event {
    NSString* chars = [event characters];
    unichar uniChar = [chars characterAtIndex: 0];
    
    switch(uniChar) {
        case 'a':
            [self makeFullScreen];
            break;
        case 27:
            exit(0);
            break;
    }
}
@end

My view extends NSOpenGLView. I'm new to this so I understand that whatever I have is probably completely wrong. I've looked at the NSOpenGL Fullscreen example provided by Apple but I'm a little lost. I've Googled my brains out and haven't really come up with anything that I've found useful. Any help would be appreciated!


Fullscreen Frustrations - backslash - Feb 10, 2009 06:18 AM

Two things stand out immediately:
1 - you have to share your windowed OpenGL context with the fullscreen conext so that your textures and things are available to both.
2 - you have to make sure the correct context is current when you want to draw. You could either do this manually at the start of drawrect: or set your fullscreen context as the context for your NSOpenGLView (which automatically makes its own context current before calling drawrect). Watch out for memory leaks if you choose that method.