iDevGames Forums
Fullscreen Frustrations - Printable Version

+- iDevGames 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:

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

- (BOOL) acceptsFirstResponder {
    return YES;

- (void) drawRect: (NSRect) bounds {
    glClearColor(0, 0, 0, 0);
        glVertex3f(  0.0,  0.6, 0.0);
        glVertex3f( -0.2, -0.3, 0.0);
        glVertex3f(  0.2, -0.3 ,0.0);

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

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.