Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Full Screen Cocoa OpenGL

Full Screen Cocoa OpenGL
Thread Tools
Meneldil
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status: Offline
Reply With Quote
Nov 5, 2003, 01:29 PM
 
I'm trying to bind the OpenGL context to the full screen, but I'm not able to because I'm unable to set NSOpenGLPFAFullScreen in the pixel format. According to Apple's Dev Center, this means my computer can't do fullscreen OpenGL. The OpenGL Info utility says that I can though, and I'd hope that it can. I have a 12" powerbook running 10.2.8.

Here is the relevant code:

Trying to set the pixel format--

- (NSOpenGLPixelFormat *) createPixelFormat;
{
NSOpenGLPixelFormatAttribute *attributes[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 32,
NSOpenGLPFAFullScreen,
nil
}; //Creates an array of attributes to be passed to NSOpenGLPixelFormat.

NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];

if ( pixelFormat == nil ) {
NSLog( @"Failed to create pixel format." );
}; //Checks to make sure that the pixel format was created.

return pixelFormat;
}

If NSOpenGLPFAFullScreen is included in the array, creating the pixel format fails. If I take it out, it succeeds. I apparently need to declare it as an attribute if I want to bind to the full screen, so I'd like to figure this out.

Here's the Dev Center link.
http://developer.apple.com/documenta...00463/CJBBIAGG
--
     
arekkusu
Mac Enthusiast
Join Date: Jul 2002
Status: Offline
Reply With Quote
Nov 5, 2003, 01:57 PM
 
You need to do two things.

First, on a laptop, you must specify _which screen_ to go fullscreen on. Even if you don't have a second display connected (svideo/vga/dvi), the system treats your machine as having two virtual screens. (desktop developers take note! test your code on laptops!)

This is pretty easy, add this to your pixel format:

NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(display),

where "display" is the CGDisplay ID, which can just be CGMainDisplayID() for the display with the menu bar, or you can get fancy with i.e. CGGetDisplaysWithRect() to choose the display where your window is located.



Secondly, you should also add:

NSOpenGLPFANoRecovery,

This one might be optional for the simple fullscreen case, but if you do anything more complex, like trying to share windowed and fullscreen contexts, then you need it.
     
Meneldil  (op)
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status: Offline
Reply With Quote
Nov 5, 2003, 02:29 PM
 
Thank you! I can now apparently create a pixel format. Now for the next error the hateful compiler keeps giving me.

2003-11-06 02:18:09.601 example[1701] First line of initGL.
2003-11-06 02:18:09.700 example[1701] Created an OpenGL context.
2003-11-06 02:18:09.703 example[1701] *** -[NSOpenGLContext cglContext]: selector not recognized
2003-11-06 02:18:09.734 example[1701] Exception raised during posting of notification. Ignored. exception: *** -[NSOpenGLContext cglContext]: selector not recognized

example has exited with status 0.

This is apparently caused by the third line in this block of code, based on the selective application of NSLog statements and looking at the errors.

CGLContextObj cglContext;
CGLError error;
cglContext = [context cglContext];
error = CGLSetFullScreen(cglContext);

This is the way the Omnigroup example does it, and that code works on my machine. The 'NSOpenGLContext *context' seems to have been successfully created.

If anyone has a quick answer, let me know, but at least this time I have a better idea what the problem is.
--
     
Meneldil  (op)
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status: Offline
Reply With Quote
Nov 5, 2003, 03:20 PM
 
I seemed to have fixed it. Even though it works in the Omni code, changing all of the context creation stuff from NS* to CGL* makes it work.
--
     
arekkusu
Mac Enthusiast
Join Date: Jul 2002
Status: Offline
Reply With Quote
Nov 5, 2003, 05:59 PM
 
The way to do it with NSOpenGLContext is [ctx setFullScreen]. Don't forget to capture the display before going fullscreen and release it afterwards otherwise other applications get their windows moved around, which is really annoying.
     
Meneldil  (op)
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status: Offline
Reply With Quote
Nov 6, 2003, 12:25 AM
 
Originally posted by arekkusu:
The way to do it with NSOpenGLContext is [ctx setFullScreen]. Don't forget to capture the display before going fullscreen and release it afterwards otherwise other applications get their windows moved around, which is really annoying.
Thanks again! All the OpenGL stuff is working perfectly now.
--
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:40 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,