I'm implementing a borderless fullscreen functionality and managed to make something that almost works. Using: C++, Winapi, OpenGL 3.3.
When in fullscreen borderless mode, if alt tab the game window loses focus but is still on top, not even the alt tab window shows.
I managed to track it down to SwapBuffers. If i disable it, no problems but also no rendering.
If i force the window to hide when it loses focus, the entire screen flickers. And if i alt tab back, only the game window flickers.
If i put the game in windowed mode, it works as normal.
Window Styles are first set to(windowed mode stops here):
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE
And then are set to(if fullscreen):
GetWindowLong(window, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW
My gameloop:
while(isRunning)
{
loopNewTime = timeGetTime();
loopDuration = (r32)(loopNewTime - loopOldTime);
loopTime = Clamp(0.0f, (loopDuration - sleepTime), 250.0f);
loopOldTime = loopNewTime;
loopAccumulator += loopTime + sleepTime;
while(loopAccumulator >= loopFixedDeltaTime)
{
if(isFocused || canRunWithoutFocus)
{
DoStuff();
}
loopAccumulator -= loopFixedDeltaTime;
}
if(isFocused || canRunWithoutFocus)
{
DoStuff();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
DrawStuff();
SwapBuffers(deviceContext);
}
framerateTimeThreshhold += loopTime + sleepTime;
++framerateCount;
if(framerateTimeThreshhold >= 1)
{
framerate = framerateCount;
framerateCount = 0;
--framerateTimeThreshhold;
}
sleepTime = Max(timeStep - loopTime, 0.0f);
Sleep((u32)sleepTime);
}
So, how can i solve this problem?
Thanks in advance.