Full Screen Switching
I'm working on an NSOpenGLView subclass to control full screen switching and so far it's looking good except when I am in full screen mode, I just have a black screen! Can anyone see why?
Code:
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self)
{
// Create the windowed and full screen contexts.
NSOpenGLPixelFormatAttribute windowedAttributes[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFANoRecovery,
NSOpenGLPFASingleRenderer,
NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
0
};
NSOpenGLPixelFormat* windowedPF = [[[NSOpenGLPixelFormat alloc] initWithAttributes: windowedAttributes] autorelease];
windowedContext = [[NSOpenGLContext alloc] initWithFormat: windowedPF shareContext: nil];
NSOpenGLPixelFormatAttribute fullScreenAttributes[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFANoRecovery,
NSOpenGLPFASingleRenderer,
NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
NSOpenGLPFAFullScreen,
0
};
NSOpenGLPixelFormat* fullScreenPF = [[[NSOpenGLPixelFormat alloc] initWithAttributes: fullScreenAttributes] autorelease];
fullScreenContext = [[NSOpenGLContext alloc] initWithFormat: fullScreenPF shareContext: windowedContext];
}
[self setOpenGLContext:windowedContext];
return self;
}
- (void)drawRect:(NSRect)rect
{
glClearColor(0.2f, 0.25f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
[[self openGLContext] flushBuffer];
}
- (IBAction) toggleFullScreen:(id)sender
{
[NSOpenGLContext clearCurrentContext];
if(isFullScreen)
{
isFullScreen = NO;
[fullScreenContext clearDrawable];
CGReleaseAllDisplays();
[self setOpenGLContext:windowedContext];
[[self window] makeKeyAndOrderFront:self];
[NSCursor unhide];
[NSMenu setMenuBarVisible:YES];
}
else
{
isFullScreen = YES;
[windowedContext clearDrawable];
CGCaptureAllDisplays();
[fullScreenContext setFullScreen];
[self setOpenGLContext:fullScreenContext];
[NSCursor hide];
[NSMenu setMenuBarVisible:NO];
}
[self display];
}
Where do you set glViewport? State like this isn't shared by contexts, only data like textures can be shared, so you'll have to call glViewport and others again after toggling full screen.
I'm not sure if that's the problem, though. Better wait for an expert. Quick question: When you exit full screen again, does everything work as expected?
I'm not sure if that's the problem, though. Better wait for an expert. Quick question: When you exit full screen again, does everything work as expected?
Well I finally fixed it by adding
to the drawRect method.
Code:
if(isFullScreen) [fullScreenContext setFullScreen];
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| switching screen resolution | NelsonMandella | 3 | 2,936 |
Apr 25, 2010 01:33 PM Last Post: SethWillits |
|
| Full Screen OpenGL Crashes | Blacktiger | 13 | 6,591 |
Feb 19, 2009 02:39 PM Last Post: backslash |
|
| OpenGL full screen mode leaves garbage on screen when exiting app | Malarkey | 5 | 4,497 |
Nov 19, 2008 12:51 PM Last Post: Malarkey |
|
| Changing resolution while already in full-screen mode? | Malarkey | 1 | 2,274 |
Jun 10, 2008 07:49 PM Last Post: AnotherJake |
|
| Dealing with Battery Low Warning During Full Screen | AnotherJake | 8 | 5,245 |
Feb 8, 2008 12:26 PM Last Post: OneSadCookie |
|

