Raptor007 / BTTT

BattleTech tabletop network/hotseat game (uses RaptorEngine).
https://www.raptor007.com/bttt/
6 stars 2 forks source link

Fix window resize/maximize #2

Open Raptor007 opened 4 weeks ago

Raptor007 commented 4 weeks ago

Resizing or maximizing the window seems to miss the SDL2 event(s) that should signal the game to resize its contents.

It might also be nice for the maximize button and/or alt+enter to toggle fullscreen mode.

Raptor007 commented 4 weeks ago

You can work around this bug in the console or settings.cfg. To change window size:

g_res_windowed_x 1920
g_res_windowed_y 1080
g_restart

To change to fullscreen mode:

g_fullscreen true
g_restart
Raptor007 commented 4 weeks ago

The problem is here: https://github.com/Raptor007/RaptorEngine/blob/master/Core/RaptorGame.cpp#L392

if( event.type == SDL_WINDOWEVENT_RESIZED )
    Gfx.SetMode( event.window.data1, event.window.data2 );

Apparently SDL_WINDOWEVENT_RESIZED is a window event subtype, not an event type, so it never matched.
New code for BTTT v0.9.9:

if( event.type == SDL_WINDOWEVENT )
{
    if( (event.window.event == SDL_WINDOWEVENT_RESIZED) && ! Gfx.Fullscreen )
        Gfx.SetMode( event.window.data1, event.window.data2 );
    else if( (event.window.event == SDL_WINDOWEVENT_MAXIMIZED) && Cfg.SettingAsBool("g_maximize_fullscreen") )
        Gfx.SetMode( 0, 0, Gfx.BPP, true, Gfx.FSAA, Gfx.AF, Gfx.ZBits );
}

Also, since SDL2 does not destroy the OpenGL context upon window resize, I've patched Graphics::SetMode( x, y ) so it'll just change the resolution-related variables without restarting graphics.