Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen vs Borderless window

Tags:

windows

winapi

My goal is to create an OpenGL application. I've seen many games that let the user decide if the "game window" will be "fullscreen" or "borderless". What's the difference? How do I implement each method?

I heard that fullscreen windows are just windows with WS_POPUP style that are set to be the width and height of the screen. Is this true for only one of the approaches I mentioned above?

What's the difference between "Borderless" and "Fullscreen" here? (screenshot taken from LoL) img

like image 736
Pilpel Avatar asked Dec 25 '15 11:12

Pilpel


2 Answers

You just need WS_POPUP and full screen width & height to hide the task bar. Here is example of changing window style after window is already shown:

if (msg == WM_LBUTTONDOWN)
{
    if (GetWindowLongPtr(hwnd, GWL_STYLE) & WS_POPUP)
    {
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW);
        SetWindowPos(hwnd, NULL, 0, 0, 600, 400, SWP_FRAMECHANGED);
    }
    else 
    {//show full-screen
        int w = GetSystemMetrics(SM_CXSCREEN);
        int h = GetSystemMetrics(SM_CYSCREEN);
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
        SetWindowPos(hwnd, HWND_TOP, 0, 0, w, h, SWP_FRAMECHANGED);
    }
}

Or to show with initial full-screen size:

int w = GetSystemMetrics(SM_CXSCREEN);
int h = GetSystemMetrics(SM_CYSCREEN);
HWND hmain = CreateWindow(L"className", L"title", WS_POPUP, 0, 0, w, h, 0, 0, hInst, 0);
ShowWindow(hmain, SW_SHOW);

Windows are either WS_OVERLAPPED, WS_POPUP, or WS_CHILD. These three flags can't be combined with each other, but they can be combined with other WS_XXXX flags.

Top windows are either WS_OVERLAPPED or WS_POPUP Different styles for main window include:

  • Normal window: WS_OVERLAPPED, shown with ShowWindow(hwnd, SW_SHOW)

  • Maximized window: WS_OVERLAPPED, shown with ShowWindow(hwnd, SW_MAXMIZE) covers the whole screen, not including the taskbar

  • Fullscreen: WS_POPUP flag, with width & height set to SM_CXSCREEN/SM_CYSCREEN, covers the whole screen, it goes over the task bar

All these windows can have WS_BORDER or not. Or they may have WS_THICKFRAME for resizing border. In fullscreen mode, the window usually has no border. In maximized mode, the borders fall outside the view area.

More details: Window Styles

like image 118
Barmak Shemirani Avatar answered Oct 17 '22 21:10

Barmak Shemirani


'Fullscreen' mode is a special mode where the game takes over the entire display and doesn't attempt to cooperate with other windows in any way. It's how all games used to work, is more flexible (your game resolution doesn't have to match your desktop resolution) and in theory faster. In practice it can cause a lot of problems when you alt-tab and suchlike. You can in some situations end up with the game window still showing when you should be using another application.

'Borderless' makes a normal window but with no title bar or border that takes up the whole screen. Visually this should be the same as Fullscreen, but avoids the interoperating problems. You can have other things on top of it (eg. taskmanager), you can alt-tab quite happily. The downside is that it may be slower because Windows gets involved in the drawing process, and you're stuck with the user's desktop resolution.

'Windowed' is a normal Windows window which always has a title bar, and may have resizing handles, minimise button and so on. This might also take up the whole screen when maximised, but the actual usable area is smaller because you lose some space to the title bar/close buttons/border.

Screen modes are generally Windows level things, rather than openGL.

To get Windowed mode you use CreateWindowEx() and pass the WS_OVERLAPPED style. To get Borderless you use the same function with WS_POPUP style. In theory, anyway. I've seen video drivers give you Fullscreen anyway. To get Fullscreen you generally apply ChangeDisplaySettings(blah,CDS_FULLSCREEN) to switch to your desired video mode.

like image 5
Andy Krouwel Avatar answered Oct 17 '22 22:10

Andy Krouwel