Display Capturing / Fading
Hi,
I've written a c++ class to handle capturing displays, changing resolution/refresh rates etc, get ready to use OpenGL, and fade in and out. The class uses Core Graphics calls to do all this and works, mostly...
My big function to capture the display and change its settings uses new 10.3 only calls to try and fade the display all pretty, but after fading in, there is a flash back to the desktop before changing display modes. Its very annoying and I've given up and am asking for help: why does this occur and how can i avoid it?
Here's my relevant code:
(Sorry if the formatting/line wrap is screwed up...)
I've written a c++ class to handle capturing displays, changing resolution/refresh rates etc, get ready to use OpenGL, and fade in and out. The class uses Core Graphics calls to do all this and works, mostly...
My big function to capture the display and change its settings uses new 10.3 only calls to try and fade the display all pretty, but after fading in, there is a flash back to the desktop before changing display modes. Its very annoying and I've given up and am asking for help: why does this occur and how can i avoid it?
Here's my relevant code:
(Sorry if the formatting/line wrap is screwed up...)
Code:
void drawContext::initContext(int requestedWidth, int requestedHeight, int requestedBitDepth)
{
fadeToBlack(4.0);
// save original display settings
originalMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
// capture display to preserve desktop icons, don't tell everybody we're switching
gameMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty(kCGDirectMainDisplay, requestedBitDepth,
requestedWidth, requestedHeight, 0,
kCGDisplayModeIsStretched, 0);
CGCaptureAllDisplaysWithOptions(kCGCaptureNoFill); ///ïïï OS 10.3 and above only!
// switch modes
CGDisplaySwitchToMode( kCGDirectMainDisplay, gameMode);
// choose a pixel format
displayMask = CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ;
CGLPixelFormatAttribute attribs[] =
{
kCGLPFAFullScreen,
kCGLPFADisplayMask,
(_CGLPixelFormatAttribute)displayMask, // these are typecast to avoid
(_CGLPixelFormatAttribute)NULL // compiler warnings, nothing else special...
}; // note, attributes must be NULL terminated!
CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats );
// Setup the full-screen context:
CGLCreateContext( pixelFormatObj, NULL, &contextObj ) ;
CGLDestroyPixelFormat( pixelFormatObj ) ;
CGLSetCurrentContext( contextObj ) ;
CGLSetFullScreen( contextObj ) ;
// find out what we actually got
gameWidth = CGDisplayPixelsWide(kCGDirectMainDisplay);
gameHeight = CGDisplayPixelsHigh(kCGDirectMainDisplay);
gameBitDepth = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
fadeFromBlack(4.0);
}
I've written some similar code if you want to check it out...
http://www.sfu.ca/~kberg/Code/Display.h
http://www.sfu.ca/~kberg/Code/Display.cpp
It has similar functions, such as using CG for gamma fades, though it uses AGLFullScreen to capture the display, and failing that can fall back on DrawSprocket to do the same.
http://www.sfu.ca/~kberg/Code/Display.h
http://www.sfu.ca/~kberg/Code/Display.cpp
It has similar functions, such as using CG for gamma fades, though it uses AGLFullScreen to capture the display, and failing that can fall back on DrawSprocket to do the same.
Thanks for the help but I wanna stay just in core graphics if possible. I've mostly solved my problem by using the CGDisplayConfiguration functions to set up a fade for a single transition rather than fading on my own before changing modes. There is still a flicker but its much less noticeable than the previous problem. If anyone has a better, completely flicker free mode switch method than I'd love to hear about it. Anyways my solution works enough, here's the relevant code:
Code:
_CGDisplayConfigRef * configRef; // used for configuring display switch
// save original display settings
originalMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
// select new mode
gameMode =
CGDisplayBestModeForParametersAndRefreshRateWithProperty(
kCGDirectMainDisplay, requestedBitDepth, requestedWidth, requestedHeight, 0,kCGDisplayModeIsStretched, 0);
// capture display to preserve desktop icons, don't tell everybody we're switching
CGCaptureAllDisplaysWithOptions(kCGCaptureNoFill); ///ïïï OS 10.3 and above only!
// setup display switch configuration
CGBeginDisplayConfiguration(&configRef);
CGConfigureDisplayFadeEffect(configRef, 3.0f, 3.0f, // 3 second fade out and in
0.0f, 0.0f, 0.0f); // fade to black
CGConfigureDisplayMode(configRef, kCGDirectMainDisplay, gameMode);
CGCompleteDisplayConfiguration(configRef, kCGConfigureForAppOnly);
// hide cursor
CGDisplayHideCursor(kCGDirectMainDisplay);
// Switch to new mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, gameMode);
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Using blending for a text fading effect. | cjcaufield | 2 | 3,493 |
Jun 30, 2010 08:21 PM Last Post: cjcaufield |
|
| glColor4f and glBlendFunc for fading to white? | dave05 | 3 | 4,475 |
Jun 24, 2005 05:31 PM Last Post: Skorche |
|

