Is there a graceful way to handle toggling between fullscreen and windowed mode in a Windows OpenGL application?

Basically it's just resizing the window and specifying flags that the border is invisible.

Up vote 6 down vote favorite 3 share g+ share fb share tw.

This is undesirable because it introduces a delay in switching between fullscreen and windowed mode, potentially a long one, as well as making it easier to screw things up by forgetting to reinitialize something. As a followup to that, are there certain visual effects that are broken by managing to do this? I've done a fair bit of searching and reading for the past few days, and despite a lot of flaming of SDL and other frameworks for having the same problem(I'm not using them anyway, but...), the best I've managed to find is a possible lead on opening a 1x1 window in the background to retain the context while a secondary window is destroyed or created at whim.

And that's seeming unreliable from the comments I found regarding it, and seems very kludgey regardless. Is there a proper way to do this, or is the proper way the often-given-as-an-example method of destroying your window, and recreating it, including destroying your OpenGL context and recreating it? C++ c winapi opengl fullscreen link|improve this question asked Aug 25 '11 at 15:37Azuvector1326 80% accept rate.

Basically it's just resizing the window and specifying flags that the border is invisible. SetWindowLongPtr(hWnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); MoveWindow(hWnd, 0, 0, width, height, TRUE); to set it back: RECT rect; rect. Left = 0; rect.

Top = 0; rect. Right = width; rect. Bottom = height; SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); MoveWindow(hWnd, 0, 0, rect.

Right-rect. Left, rect. Bottom-rect.

Top, TRUE); or for a not-resizable window: SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); MoveWindow(hWnd, 0, 0, rect. Right-rect. Left, rect.

Bottom-rect. Top, TRUE); and then just resize your OpenGL viewport settings. If you want to set the display mode too, use this: // change display mode if destination mode is fullscreen if (fullscreen) { DEVMODE dm; dm.

DmSize = sizeof(DEVMODE); dm. DmPelsWidth = width; dm. DmPelsHeight = height; dm.

DmBitsPerPel = bitsPerPixel; dm. DmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; success = ChangeDisplaySettings(&dm, 0) == DISP_CHANGE_SUCCESSFUL; } // reset display mode if destination mode is windowed if (!fullscreen) success = ChangeDisplaySettings(0, 0) == DISP_CHANGE_SUCCESSFUL.

That answers my question almost perfectly, thank you. However, I have run into another odd problem... Once I return to windowed mode, I have leftover data from my fullscreen drawing still hanging around. Nothing I've tried(InvalidateRect(), RedrawWindow(), ChangeDisplaySettings()) seems to work at causing the screen to repaint itself.

(I ended up using ChangeDisplaySettings(&saved, 0) and a workaround of using ShowWindow(hwnd, SW_HIDE) just before ChangeDisplaySettings(), except the window loses focus for a moment and thus can have its input grabbed by some other app. Is there a better option? – Azuvector Aug 26 '11 at 8:07 1 I found a bit of extra info.

Apparently you want to use SetWindowPos() rather than MoveWindow(), when using SetWindowLongPtr(). Also, using ChangeDisplaySettings(NULL, 0) AFTER resizing my window appears to fix issues with dirty backgrounds. – Azuvector Aug 29 '11 at 3:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions