SDL change fullscreen mode

Started by
8 comments, last by BloodLust666 17 years, 10 months ago
for some reason, the function SDL_WM_ToggleFullScreen() isn't working... i'm passing SDL_GetVideoSurface() into the function too
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
It doesnt work on win32,but you can just create a new sdl surface and add the fullscreen bitmask to the current flags (if you know what they are).
when i do that, none of my textures are coming out and everything i render is just a white rectangle...

here's the code:

	bool cWGraphics::ChangeScreenMode(bool Fullscreen)	{		if ((SDL_WasInit(SDL_INIT_VIDEO) != 0) && (Fullscreen != m_bFullScreen))		{					m_bFullScreen = Fullscreen;					const SDL_VideoInfo *Info = NULL;			int flag = SDL_OPENGL;			if (Fullscreen == true) 				flag |= SDL_FULLSCREEN;						SDL_QuitSubSystem(SDL_INIT_VIDEO);			if ( SDL_InitSubSystem( SDL_INIT_VIDEO ) < 0)				return cWUtility::ErrorLog.Write("cWGraphics::Init() SDL failed");			SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);			SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5);			SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5);			SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5);			SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);			SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 16);			SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);			if ((Info = SDL_GetVideoInfo()) == NULL)				return cWUtility::ErrorLog.Write("cWGraphics::Init() No Info");			if (SDL_SetVideoMode( m_lBufferWidth, m_lBufferHeight, Info->vfmt->BitsPerPixel, flag) == NULL)				return cWUtility::ErrorLog.Write("cWGraphics::Init() SetVideoMode() failed");						// Re-Initialize OpenGL			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);			glClearDepth(1.0f);			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);			glFrontFace(GL_CCW);			glShadeModel(GL_SMOOTH);			glEnable(GL_DEPTH_TEST);			glEnable(GL_CULL_FACE);			glEnable(GL_LIGHTING);			glEnable(GL_LIGHT0);		} else			cWUtility::ErrorLog.Write("cWGraphics::ChangeScreenMode() Not Init'ed first");	}
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
SDL destroys the openGL context on calls to SDL_SetVideoMode, you lose all the stuff like textures or display lists. You will need to reload them.
is there an easier way to change the fullscreen mode without having to reload everything? oh, and i'm using it with opengl so my textures are in the opengl if that matters.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
is there an easier way to change the fullscreen mode without having to reload everything? oh, and i'm using it with opengl so my textures are in the opengl if that matters.


Well, I don't think this is supported behaviour, but on windows (IIRC) if you just react to the SDL_RESIZE event by calling glViewport with the new window size, the window has already been resized by SDL. If you do this then you cannot depend on the values of SDL_GetVideoSurface()->w or ->h, so you must record the actual window size yourself, should you need it.

Seeing as you are not using the SDL blit functions, this might work.

[edited to be in keeping to what I was trying to say, sorry]

[Edited by - rip-off on May 29, 2006 7:46:11 AM]
that won't work.. setting the viewport on changes the size of the camera view, it doesn't change the actual window size. i use that effect for 2D camera zooming.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
that won't work.. setting the viewport on changes the size of the camera view, it doesn't change the actual window size. i use that effect for 2D camera zooming.


No, thats not what I meant at all [smile]. What I meant is that if you use the SDL_RESIZEABLE flag, and don't react to resize events, te window is still resized. Its like SDL resizes the window before you get the event, or possibly the win32 subsystem. If you don't react to the event however, your viewport may no longer fit the window. So if you recall the viewport and camera setup code with the windows resized width and height values, it seems to work.

Try it out yourself, comment out any code that reacts to SDL_VIDEORESIZE events, and add the SDL_RESIZABLE flag to your SDL_SetVideoMode() call, and change the window size. On my system, the window changes size without any need to call SDL_SetVideoMode again.

But again I say that I found this to be the case on windows, I cannot guarentee the same behaviour on other platforms.

And yes I have tested this just now.

case SDL_VIDEORESIZE:    int w,h;    w = event.resize.w; h = event.resize.h;    glViewport( 0, 0, w, h );    glMatrixMode( GL_PROJECTION );    glLoadIdentity();    gluOrtho2D( 0, w, 0, h );    glMatrixMode( GL_MODELVIEW );    glLoadIdentity();    break;


I'm not sure how (if) this would work well with any of SDLs functrions that depend on the video screen, particularly the blit function. But for opengl it *seems* to work fine.

Now I feel dirty for pushing this undocumented behaviour. [smile]
Quote:Original post by rip-off
Quote:Original post by EvilKnuckles666
that won't work.. setting the viewport on changes the size of the camera view, it doesn't change the actual window size. i use that effect for 2D camera zooming.


No, thats not what I meant at all [smile]. What I meant is that if you use the SDL_RESIZEABLE flag, and don't react to resize events, te window is still resized. Its like SDL resizes the window before you get the event, or possibly the win32 subsystem. If you don't react to the event however, your viewport may no longer fit the window. So if you recall the viewport and camera setup code with the windows resized width and height values, it seems to work.

Try it out yourself, comment out any code that reacts to SDL_VIDEORESIZE events, and add the SDL_RESIZABLE flag to your SDL_SetVideoMode() call, and change the window size. On my system, the window changes size without any need to call SDL_SetVideoMode again.

But again I say that I found this to be the case on windows, I cannot guarentee the same behaviour on other platforms.

And yes I have tested this just now.

*** Source Snippet Removed ***

I'm not sure how (if) this would work well with any of SDLs functrions that depend on the video screen, particularly the blit function. But for opengl it *seems* to work fine.

Now I feel dirty for pushing this undocumented behaviour. [smile]


I think it might be the case on windows - only. If you are blitting with SDL and resize the window (no new SDL_SetVideoSurface() call) with just window's way of doing it, you are making the frame larger but not the drawing area.

Thus anything with SDL will *still* be in that old area.

But my conclusion is that OpenGL is O.K. with the new area that windows let it have and is able to draw over it...

I could be wrong, though.
wait, wait, i'm not resizing the window at all; i'm just looking to swap between fullscreen and windowed mode
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML

This topic is closed to new replies.

Advertisement