Fullscreen/Window Setup/toggle

Moderator
Posts: 916
Joined: 2002.10
Post: #1
I'm using Objective C++ (so I have all those options). In the past I'd just inherit from NSOpenGLView and have a set view in a window to work in. This was great for the most part (as I like playing games in a window, even if the window takes up most of the screen).

But time has come for me to be able to do both windowed and fullscreen, and toggle. Advice on how to do this? Code? Donuts? Ninja
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
much love cookie
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #4
m'k, it toggles. but the code I use in drawrect doesn't draw when in full screen. In fact, the full screen view is all black. What's up?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
You need to be careful about which OpenGL context is current, particularly given that NSOpenGLView likes to mess with it behind your back. Check the example code, it works Rasp
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #6
Something that bit me bad is that if you're sharing contexts, it doesn't share state. Even if you use the copyState selector, it doesn't copy things like the projection matrix.

If you're not setting up your projection again after the switch, you're dead. Bang.
Quote this message in a reply
Member
Posts: 72
Joined: 2006.10
Post: #7
That's actually a great feature of context sharing. Say you have two NSOpenGLView displaying stuff at the same time. Both are going to have their own context, and each will have their own state. However, they can share ressources in order to save VRAM. This way, you can have the same scene seen from different point of views (and/or with different shaders enabled) each in their own window.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #8
the code below is crashing between a = 2 and a=3
Code:
if (_fullScreenContext != nil)
        {
                        int a=0;
                        NSLog(@"%d",a++);       //0
            [_windowedContext clearDrawable];
                        NSLog(@"%d",a++);
            CGCaptureAllDisplays();
                        NSLog(@"%d",a++);       // 2
            CGDisplaySwitchToMode(kCGDirectMainDisplay, (CFDictionaryRef)_fullScreenMode);
                        NSLog(@"%d",a++);
            [_fullScreenContext setFullScreen];
                        NSLog(@"%d",a++);       //4
            [_fullScreenContext makeCurrentContext];
                        NSLog(@"%d",a++);
            _fullScreen = YES;
                        NSLog(@"%d",a++);       //6
                        NSSize contextSize;
                        NSLog(@"%d",a++);
                        contextSize.width = CGDisplayPixelsWide(kCGDirectMainDisplay);
                        NSLog(@"%d",a++);       //8
                        contextSize.height = CGDisplayPixelsHigh(kCGDirectMainDisplay);
                        NSLog(@"%d",a++);
                        GSEventOpenGLContextStateInvalidated();
                        NSLog(@"%d",a++);       //10
                        GSEventOpenGLContextResized(contextSize.width, contextSize.height);
                        NSLog(@"%d",a++);
        }
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #9
Quote:That's actually a great feature of context sharing.
Agreed, I just made the stupid assumption that they did share state more thoroughly and spent a month debugging. Wink
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
skyhawk Wrote:the code below is crashing between a = 2 and a=3
Code:
CGDisplaySwitchToMode(kCGDirectMainDisplay, (CFDictionaryRef)_fullScreenMode);

Then _fullScreenMode must be invalid in some way...

-Keith
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #11
I'm pretty sure it is not set to anything anywhere.

EDIT: I see my issue, I'll let you know if the fix works later tonight
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL. How to hide fullscreen window e40pud 1 4,015 Mar 11, 2010 01:23 PM
Last Post: cmiller
  bug in OpenGL setup for NSOpenGL subclass (I think) backslash 2 3,693 Jul 18, 2007 01:10 PM
Last Post: backslash
  xCode/SDL Setup hammonjj 2 4,711 Mar 2, 2007 06:37 AM
Last Post: hammonjj
  Copying from OpenGL window to other window Ingemar 7 4,787 Nov 4, 2006 03:50 AM
Last Post: OneSadCookie
  Testing GL Setup Code (Help Wanted) Matrix 8 3,911 Sep 11, 2006 04:06 PM
Last Post: sjstux