setting window to fullscreen introduces delay

62 Views Asked by At

I am making a simple game and i want to set my main window to fullscreen mode. I do this with the SDL_SetWindowFullscreen but it takes some time to display the window. I want to freeze the game time during that setting the window mode period. Is there any way i can get the state of the window display mode so that i can ensure when to pause and when to resume the game clock?

Thank you in advance!

First i tried pushing my own event to the SDL2 event queue, after SDL initialization. To handle the event i checked the window flags with SDL_GetWindowFlags against the desired fullscreen mode. If the flag is not set yet, push the own made event again. Did not work.

Then, i tried utilizing the SDL_WINDOWEVENT_EXPOSED and SDL_WINDOWEVENT_FOCUS_GAINED with flags. Something like this:

GameMemory->starttime = SDL_GetTicks();
while(SDL_PollEvent(&GameMemory->event))
{
   // Handle Events.
   switch(GameMemory->event.window.event)
   {
       case(SDL_WINDOWEVENT_EXPOSED):
       {
           if(GameMemory->isBooting)
           {
               GameMemory->isBooting = false;
               GameMemory->isPaused  = false;
           }
           break;
       }
       case(SDL_WINDOWEVENT_FOCUS_GAINED):
       {
           if(GameMemory->isBooting == false)
           {
               GameMemory->isPaused  = false;
               SDL_ShowCursor(false);
           }
           break;
       }
       case(SDL_WINDOWEVENT_FOCUS_LOST):
       {
           if(GameMemory->isBooting == false)
           {
               GameMemory->isPaused  = true;
               SDL_ShowCursor(true);
           }
           break;
       }
       default:
           break;
   }
}

Did not work either.

1

There are 1 best solutions below

1
Builderboy271 On

I don't know where you are switching to fullscreen mode, but you should be able to pause the game time before you set the mode to fullscreen, and then resume the game time after:

GameMemory->isPaused  = true;
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
GameMemory->isPaused  = false;