Trouble with going fullscreen

Moderator
Posts: 916
Joined: 2002.10
Post: #1
I am going full screen and it is not drawing anything... (it draws stuff fine in windowed mode) I get these kind of errors:
2003-07-15 00:45:14.892 AppName[1327] invalid drawable

I'm drawing in an OGL context... maybe someone else has had this problem. Any idea what I am doing wrong?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Your pixel format is not compatible with the current screen mode, most likely.

Are you specifying NSOpenGLPFAFullScreen in your pixel format? Do you request a particular number of colors, and does that match the mode you've switched to? Anything else potentially unusual we should know about?
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
in the glView's awakefromnib I call:
Code:
originalDisplayMode = (NSDictionary *) CGDisplayCurrentMode(kCGDirectMainDisplay );
runningFullScreen=true;
[self initWithFrame:NSMakeRect( 0, 0, 640, 480 ) colorBits:32 depthBits:32 fullscreen:true];
and here is the rest of that initing code...
Code:
- (id) initWithFrame:(NSRect)frame colorBits:(int)numColorBits depthBits:(int)numDepthBits fullscreen:(BOOL)runFullScreen
{
   NSOpenGLPixelFormat *pixelFormat;

   colorBits = numColorBits;
   depthBits = numDepthBits;
   runningFullScreen = runFullScreen;
   originalDisplayMode = (NSDictionary *) CGDisplayCurrentMode( kCGDirectMainDisplay );
   pixelFormat = [ self createPixelFormat:frame ];
   if( pixelFormat != nil )
   {
      self = [ super initWithFrame:frame pixelFormat:pixelFormat ];
      [ pixelFormat release ];
      if( self )
      {
         [ [ self openGLContext ] makeCurrentContext ];
         if( runningFullScreen )
            [ [ self openGLContext ] setFullScreen ];
         [ self reshape ];
         if( ![ self initGL ] )
         {
            [ self clearGLContext ];
            self = nil;
         }
      }
   }
   else
      self = nil;

   return self;
}

- (void) reshape
{
   NSRect sceneBounds;
  
   [ [ self openGLContext ] update ];
   sceneBounds = [ self bounds ];
   // Reset current viewport
   glMatrixMode( GL_PROJECTION );   // Select the projection matrix
   glOrtho(0,scrwidth,scrheight,0,-20,20);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();                // and reset it
}

- (NSOpenGLPixelFormat *) createPixelFormat:(NSRect)frame
{
   NSOpenGLPixelFormatAttribute pixelAttribs[ 16 ];
   int pixNum = 0;
   NSDictionary *fullScreenMode;
   NSOpenGLPixelFormat *pixelFormat;

   pixelAttribs[ pixNum++ ] = NSOpenGLPFADoubleBuffer;
   pixelAttribs[ pixNum++ ] = NSOpenGLPFAAccelerated;
   pixelAttribs[ pixNum++ ] = NSOpenGLPFAColorSize;
   pixelAttribs[ pixNum++ ] = colorBits;
   pixelAttribs[ pixNum++ ] = NSOpenGLPFADepthSize;
   pixelAttribs[ pixNum++ ] = depthBits;

   if( runningFullScreen )  // 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 ];

   return pixelFormat;
}
- (BOOL) setFullScreen:(BOOL)enableFS inFrame:(NSRect)frame
{
   BOOL success = FALSE;
   NSOpenGLPixelFormat *pixelFormat;
   NSOpenGLContext *newContext;

   [ [ self openGLContext ] clearDrawable ];
   if( runningFullScreen )
      [ self switchToOriginalDisplayMode ];
   runningFullScreen = enableFS;
   pixelFormat = [ self createPixelFormat:frame ];
   if( pixelFormat != nil )
   {
      newContext = [ [ NSOpenGLContext alloc ] initWithFormat:pixelFormat
                     shareContext:nil ];
      if( newContext != nil )
      {
         [ super setFrame:frame ];
         [ super setOpenGLContext:newContext ];
         [ newContext makeCurrentContext ];
         if( runningFullScreen )
            [ newContext setFullScreen ];
         [ self reshape ];
         success = TRUE;
      }
      [ pixelFormat release ];
   }
   if( !success && runningFullScreen )
      [ self switchToOriginalDisplayMode ];

   return success;
}


/*
* Switch to the display mode in which we originally began
*/
- (void) switchToOriginalDisplayMode
{
   CGDisplaySwitchToMode( kCGDirectMainDisplay,
                          (CFDictionaryRef) originalDisplayMode );
   CGDisplayShowCursor( kCGDirectMainDisplay );
   CGDisplayRelease( kCGDirectMainDisplay );
}
- (BOOL) initGL
{

   glShadeModel( GL_SMOOTH );                // Enable smooth shading
   glClearColor( 0.0f, 0.0f, 0.0f,0 );   // Black background
   glClearDepth( 1.0f );                     // Depth buffer setup
   glEnable( GL_DEPTH_TEST );               // Disable depth testing
   glEnable( GL_BLEND );                     // Enable blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);     // Type of blending to perform
   // Really nice point smoothing
   glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
   glEnable( GL_TEXTURE_2D );                // Enable texture mapping
  
   return TRUE;
}
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
I'm guessing NSOpenGLView is trying to -setView: on its NSOpenGLContext, which (due to your fullscreen pixel format) doesn't work.

Just a guess though.

I'm curious as to why you're making the context current before you set the drawable, too...
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #5
Quote:Originally posted by OneSadCookie
\I'm curious as to why you're making the context current before you set the drawable, too...


point out/ highlite where...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Quote:
Code:
[ [ self openGLContext ] makeCurrentContext ];
         if( runningFullScreen )
            [ [ self openGLContext ] setFullScreen ];

(in -initWithFrame:&c)

and

Quote:
Code:
[ newContext makeCurrentContext ];
         if( runningFullScreen )
            [ newContext setFullScreen ];

(in -setFullScreen:&c)
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #7
I had that problem once, and I fixed it by adding something to the - reshape function. Unfortuanately I can't remember what it was...

its a case of the blind leading the blind here but my reshape function is:

Code:
NSSize bound = [self frame].size;
    glViewport(0, 0, bound.width, bound.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho( 0.0f,  bound.width, 0.0f, bound.height, -1.0f, 1.0f );
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


The main difference I can see is the viewport() call , though it could be doing more harm than good, or nothing at all, as like you I don't really know what my code does. Worth trying maybe....

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #8
reubert, your suggestioncode didn't work.

OSC, making context before drawable didn't seem to have an affect

>> I'm guessing NSOpenGLView is trying to -setView: on its NSOpenGLContext, which (due to your fullscreen pixel format) doesn't work.

How would I go about fixing that?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
Don't use NSOpenGLView (or at least not for fullscreen).
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #10
more help? pppllleeeeeaaasseeee
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
Don't use NSOpenGLView.

Use NSOpenGLContext directly, and attach that to an ordinary NSView in your window for windowed mode, and don't attach it to any view for fullscreen.

Is that enough?
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #12
Try the tutorials from Deep Cocoa they run in both window and fullscreen mode. http://zerobyzero.ca/~ktatters/tutorials/

Iceman
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
You should look at Fëanor's thread on a similar topic. You might find something useful there.
Quote this message in a reply
Jammer
Unregistered
 
Post: #14
The code you are using is the code from Bryan Blackburn's cocoa enhancements to the NeHe Tutorials and works fine. I too had the problem you are having but was creating a subclass of NSOpenGLView in IB and adding it to a window in the .nib. I was never able to get it to work this way. If, as Bryan's tutorials show, you [[NSOpenGLView alloc] initFrame: colorbits: depthBits: fullScreen:] in the separate Controller class's -awakeFromNib and don't use a view in the .nib file's NSWindow, the code should work as listed. I have added:

case NSF12FunctionKey:
[self setFullScreen:self];
break;

in the Controller's -keyDown: method's switch() statement and can switch between windowed and full screen at a keypress. The view class code you have provided should work as is, except that you have -awakeFromNib init calls to -initFrame in the view class itself and again, I was never able to get that to work for full screen switching.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #15
Quote:Originally posted by Jammer
The code you are using is the code from Bryan Blackburn's cocoa enhancements to the NeHe Tutorials and works fine. I too had the problem you are having but was creating a subclass of NSOpenGLView in IB and adding it to a window in the .nib. I was never able to get it to work this way. If, as Bryan's tutorials show, you [[NSOpenGLView alloc] initFrame: colorbits: depthBits: fullScreen:] in the separate Controller class's -awakeFromNib and don't use a view in the .nib file's NSWindow, the code should work as listed. I have added:

case NSF12FunctionKey:
[self setFullScreen:self];
break;

in the Controller's -keyDown: method's switch() statement and can switch between windowed and full screen at a keypress. The view class code you have provided should work as is, except that you have -awakeFromNib init calls to -initFrame in the view class itself and again, I was never able to get that to work for full screen switching.


Thanks, as stated in the other thread, I will be rewriting/restructuring my code, so that I can conquer this full screen thing. After all this... Apple should definitely make an easy to use API for going fullscreen and resolution switching and all.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble with fullscreen switching codeman9 14 5,489 Aug 11, 2004 01:37 PM
Last Post: arekkusu