The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL + Mac OSX (Cocoa)
Neo_Darkboy


Joined: 04 Mar 2011
Posts: 5
Hi all, i'm currently working with SDL on Mac and have a problem making the window fullscreen, it works fine when the application starts in Fullscreen with SetVideoMode and SDL_FULLSCREEN flag, but when i want to switch between window and fullscreen the screen is black and nothing is rendered, anyone can help me with this?


Thank's


Carlos
Jesse A.


Joined: 19 Sep 2009
Posts: 43
I don't have an answer, but here's some info that might be useful:

- SDL version (e.g. 1.2.x or 1.3)
- OS X version
- Video card
- How you're switching between windowed and fullscreen modes

(I know you mentioned SetVideoMode, which suggests 1.2.x, but as I understand it that function is still around for compatibility reasons, so I suppose you might be using 1.3.)
Neo_Darkboy


Joined: 04 Mar 2011
Posts: 5
Ok, here is the info:

- I'm using 1.2.14 SDL version
- The OS X Version is 10.6
- Intel gma 950

To switch between window and fullscreen i'm using the following code:

flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | SDL_RESIZABLE;

if(flags & SDL_FULLSCREEN)
flags &= ~SDL_FULLSCREEN;
else
flags |= SDL_FULLSCREEN;

screen = SDL_SetVideoMode( m_screenWidth, m_screenHeight, 0, flags );

after that i check if screen is null, then i set the video to the previous without the SDL_FULLSCREEN flag.

But screen is not null at this point, the windows switch to fullscreen, but everything is black, and if i switch back to windows, still remains black, so what do you think is the problem? i've tried recreating the open gl context with no result
Jesse A.


Joined: 19 Sep 2009
Posts: 43
Neo_Darkboy wrote:
i've tried recreating the open gl context with no result

How are you recreating the OpenGL context? (I don't recall that being exposed directly in SDL 1.2.x.)
Neo_Darkboy


Joined: 04 Mar 2011
Posts: 5
well actually i'm not recreating it, just setting some attributes:

Code:
      if (pixelSize==16) {
            SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 4 );
            SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 4 );
            SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 4 );
            SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 4 );
         } else {
            SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
            SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
            SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
            SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
         }
         
         SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, zBufferSize);
         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
         
         if(useStencilbuffer) {
            SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1);
         } else {
            SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);
         }


but i dont think that's the problem, i think i'm missing something, could you help me with this please?
Jesse A.


Joined: 19 Sep 2009
Posts: 43
I can't remember exactly which circumstances exhibit this behavior (I think it depends, among other things, on SDL version, OS, and the action being performed), but I think in some cases resetting the video mode will lose the OpenGL context. This means that all state - including, among other things, transforms and texture objects - will be lost and will need to be reinitialized after a video restart.

If you're using textures, try unloading them (glDeleteTextures()) before resetting the video mode, and reloading them afterwards. Also, make sure that after resetting the video mode you reset the OpenGL state as needed. (Assuming, of course, that that's the cause of the problem you're seeing.)
Neo_Darkboy


Joined: 04 Mar 2011
Posts: 5
In fact, the OpenGL context is lose after toggling the fullscreen/window, but will be painful to reload all the textures in every switch, so i think the best choice is to use the cocoa api instead of sdl, because i need some control of the window that sdl cannot let to work, like minimize in fullscreen, show pop up dialogs, etc.


Thanks for your answers!
SDL + Mac OSX (Cocoa)
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
SDL 1.3 handles those things just fine, and doesn't lose OpenGL context while toggling fullscreen/windowed mode.

On Tue, Mar 8, 2011 at 4:51 PM, Neo_Darkboy wrote:
Quote:
In fact, the OpenGL context is lose after toggling the fullscreen/window, but will be painful to reload all the textures in every switch, so i think the best choice is to use the cocoa api instead of sdl, because i need some control of the window that sdl cannot let to work, like minimize in fullscreen, show pop up dialogs, etc.


Thanks for your answers!


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
    -Sam Lantinga, Founder and CEO, Galaxy Gameworks
SDL + Mac OSX (Cocoa)
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
You can check out a pre-release snapshot here:
http://www.libsdl.org/tmp/SDL-1.3.zip

On Tue, Mar 8, 2011 at 5:15 PM, Sam Lantinga wrote:
Quote:
SDL 1.3 handles those things just fine, and doesn't lose OpenGL context while toggling fullscreen/windowed mode.

On Tue, Mar 8, 2011 at 4:51 PM, Neo_Darkboy wrote:

Quote:
In fact, the OpenGL context is lose after toggling the fullscreen/window, but will be painful to reload all the textures in every switch, so i think the best choice is to use the cocoa api instead of sdl, because i need some control of the window that sdl cannot let to work, like minimize in fullscreen, show pop up dialogs, etc.


Thanks for your answers!



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
    -Sam Lantinga, Founder and CEO, Galaxy Gameworks




--
    -Sam Lantinga, Founder and CEO, Galaxy Gameworks
SDL + Mac OSX (Cocoa)
Armin Ronacher
Guest

Hi,

On 3/4/11 2:31 AM, Neo_Darkboy wrote:
Quote:
Hi all, i'm currently working with SDL on Mac and have a problem making
the window fullscreen, it works fine when the application starts in
Fullscreen with SetVideoMode and SDL_FULLSCREEN flag, but when i want to
switch between window and fullscreen the screen is black and nothing is
rendered, anyone can help me with this?
This problem is fixed in SDL 1.3 but I would not recommend
SDL_FULLSCREEN on OS X. The reason for this is that fullscreen mode on
OS X means the application has exclusive access to the keyboard and a
bunch of other things and OS X will not provide an fast application
switcher then (cmd+tab).

Instead I am currently using something along these lines:

#if PD_PLATFORM == PD_PLATFORM_OSX
int flags = SDL_GetWindowFlags(m_win);
SDL_Window *new_win;
if (value) {
/* we cannot toggle borderless and regular window mode, so we have
to recreate the window. Sucks but well but works. */
SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplay(m_win), &mode);
new_win = SDL_CreateWindow(SDL_GetWindowTitle(m_win),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
mode.w, mode.h,
flags | SDL_WINDOW_BORDERLESS);
SDL_GetWindowDisplayMode(m_win, &mode);
m_osx_alternative_width = (size_t)mode.w;
m_osx_alternative_height = (size_t)mode.h;
} else {
/* same thing, different direction */
new_win = SDL_CreateWindow(SDL_GetWindowTitle(m_win),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
(int)m_osx_alternative_width, (int)m_osx_alternative_height,
flags & ~SDL_WINDOW_BORDERLESS);
}
SDL_DestroyWindow(m_win);
m_win = new_win;
SetSystemUIMode(value ? kUIModeAllHidden : kUIModeNormal, 0);
SDL_GL_MakeCurrent(m_win, m_glctx);

Apparently the Mac version of HoN (a dota clone) has exclusive screen
access and still supports cmd+tab. I don't own the game and a friend of
mine told me they support that so I have no idea how the managed to
accomplish that. If anyone knows, it would be nice figuring that out
and maybe even implement it in SDL itself. The downside of my solution
is that it only supports fullscreen for native screen sizes which is
annoying for notebook users with high resolution screens. The OS X
graphics devices are often not powerful enough to render at that resolution.


Regards,
Armin
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Neo_Darkboy


Joined: 04 Mar 2011
Posts: 5
wow, that is a nice solution, creating a new window, but i have the same problem that you have, the events are not received in fullscreen mode, and i need to support cmd+tab, command + m, command + shift + eject, etc, but it will require a lot of investigation, what i've found, is that may be, when the app is in fullscreen mode, is on the top level of all events/applications or something like that, and that's why the events are not received. And there is some code to do in cocoa that make the window not to be at top, so it can receive all kind of events, but i have not check the documentation to see how this works, may be this could help you
SDL + Mac OSX (Cocoa)
Eric Wing
Guest

Quote:
This problem is fixed in SDL 1.3 but I would not recommend
SDL_FULLSCREEN on OS X. The reason for this is that fullscreen mode on
OS X means the application has exclusive access to the keyboard and a
bunch of other things and OS X will not provide an fast application
switcher then (cmd+tab).

I haven't checked the new 1.3 code yet. Are we using NSView's
enterFullScreen:withOptions:? Apple changes how to do fullscreen every
few years. As I understand it, this is the one they want us to use
now. It should behave more as a Mac user expects provided you can pass
it the correct "options".

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL + Mac OSX (Cocoa)
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
No, we're using the real mode change code.

enterFullScreen:withOptions just puts a shielding window up over the current resolution, and for some reason actually crashes with the SDL view.

On Thu, Mar 10, 2011 at 8:41 PM, Eric Wing wrote:
Quote:
> This problem is fixed in SDL 1.3 but I would not recommend
Quote:
SDL_FULLSCREEN on OS X.  The reason for this is that fullscreen mode on
OS X means the application has exclusive access to the keyboard and a
bunch of other things and OS X will not provide an fast application
switcher then (cmd+tab).


I haven't checked the new 1.3 code yet. Are we using NSView's
enterFullScreen:withOptions:? Apple changes how to do fullscreen every
few years. As I understand it, this is the one they want us to use
now. It should behave more as a Mac user expects provided you can pass
it the correct "options".

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





--
    -Sam Lantinga, Founder and CEO, Galaxy Gameworks
SDL + Mac OSX (Cocoa)
Eric Wing
Guest

On 3/10/11, Sam Lantinga wrote:
Quote:
No, we're using the real mode change code.

enterFullScreen:withOptions just puts a shielding window up over the current
resolution, and for some reason actually crashes with the SDL view.

I don't know if things have changed, but I asked some Apple OpenGL
engineers about this a couple of years ago. They said they were
optimizing for this case and they intend the API to do the right thing
depending on the case.

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL + Mac OSX (Cocoa)
Armin Ronacher
Guest

Hi,

On 3/10/11 11:41 PM, Eric Wing wrote:
Quote:
I haven't checked the new 1.3 code yet. Are we using NSView's
enterFullScreen:withOptions:? Apple changes how to do fullscreen every
few years. As I understand it, this is the one they want us to use
now. It should behave more as a Mac user expects provided you can pass
it the correct "options".
I haven't checked Lion yet but I am pretty sure that their new
fullscreen support might also have some implications in how OpenGL is
supposed to work.


Regards,
Armin
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org