PDA

View Full Version : Fullscreen troubles (Cocoa)


DJBlufire
2003.12.12, 09:51 PM
This code goes in a method where i'm creating a pixel format. If we are trying to switch into fullscreen, it then goes to add a fullscreen attribute and do some funky calls to CGL (i got this code from the cocoa NeHe examples) The problem is that at the end, pixelFormat ends up as being nil. Any idea on what the problem is?


if( fullscreen ) // Do this before getting the pixel format
{
pixelAttribs[ pixNum++ ] = NSOpenGLPFAFullScreen;
fullScreenMode = (NSDictionary *) CGDisplayBestModeForParameters(
kCGDirectMainDisplay,
colorBits, frame.size.width,
frame.size.height, NULL );
CGDisplayCapture( kCGDirectMainDisplay );
CGDisplayHideCursor( kCGDirectMainDisplay );
CGDisplaySwitchToMode( kCGDirectMainDisplay,
(CFDictionaryRef) fullScreenMode );
}
pixelAttribs[ pixNum ] = 0;
pixelFormat = [ [ NSOpenGLPixelFormat alloc ]
initWithAttributes:pixelAttribs ];


PS: No compiler warnings, no NSLog warnings (except for the one I put in that tells me pixelFormat is nil).

FCCovett
2003.12.12, 10:53 PM
Are you sure pixelNum is not falling outsite the pixelAttribs[] array?

DJBlufire
2003.12.12, 11:00 PM
This is the declaration of pixelAttribs:


NSOpenGLPixelFormatAttribute pixelAttribs[ 16 ];


By the time it hits the code I showed you, pixNum should be 6, and that's the fullscreen attribute is the last one that is added. Index #7 is the '0' to terminate the array.

Also, fullScreenMode turns out not to be nil, if that helps.. pixelFormat is nil right after the point where I call the initWithAttribs method. (gah, i keep thinking "NULL"... i'm a C++ convert :)

kelvin
2003.12.12, 11:41 PM
Originally posted by DJBlufire
This code goes in a method where i'm creating a pixel format. If we are trying to switch into fullscreen, it then goes to add a fullscreen attribute and do some funky calls to CGL (i got this code from the cocoa NeHe examples) The problem is that at the end, pixelFormat ends up as being nil. Any idea on what the problem is?


if( fullscreen ) // Do this before getting the pixel format
{
pixelAttribs[ pixNum++ ] = NSOpenGLPFAFullScreen;
fullScreenMode = (NSDictionary *) CGDisplayBestModeForParameters(
kCGDirectMainDisplay,
colorBits, frame.size.width,
frame.size.height, NULL );
CGDisplayCapture( kCGDirectMainDisplay );
CGDisplayHideCursor( kCGDirectMainDisplay );
CGDisplaySwitchToMode( kCGDirectMainDisplay,
(CFDictionaryRef) fullScreenMode );
}
pixelAttribs[ pixNum ] = 0;
pixelFormat = [ [ NSOpenGLPixelFormat alloc ]
initWithAttributes:pixelAttribs ];


PS: No compiler warnings, no NSLog warnings (except for the one I put in that tells me pixelFormat is nil). What other attributes are you setting?

These are the attributes I use:NSOpenGLPixelFormatAttribute attr[] = {
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery,
NSOpenGLPFASingleRenderer,
NSOpenGLPFAColorSize,
CGDisplayBitsPerPixel(kCGDirectMainDisplay),
NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDispla y),
NSOpenGLPFAFullScreen,
NULL };

DJBlufire
2003.12.13, 02:08 AM
Wow, nice... it works! Seems that was the problem. Thanks! Only problem is that when switching out of fullscreen, the screen turns to jibberish for a second before it switches, is there a fix for this? No biggie though, I've seen it happen on some commercial games.

kelvin
2003.12.13, 02:36 AM
Originally posted by DJBlufire
Wow, nice... it works! Seems that was the problem. Thanks! Only problem is that when switching out of fullscreen, the screen turns to jibberish for a second before it switches, is there a fix for this? No biggie though, I've seen it happen on some commercial games. glClear() and switch back before releasing the context. Also using fading might help.