From 189eac273ba14c8ca0d22b31182b030ccc4c7756 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 25 Dec 2021 22:01:57 -0800 Subject: *: introduce a projection matrix and winmodes The bulk of this is mechanical wiring up of a projection_x to all the nodes. But this also introduces maintenance of the projection_x, with aspect-ratio preservation in two of the modes: WINDOWED and FULLSCREEN, with the previously default stretched-to-fill fullscreen mode now relegated to a third FILLSCREEN winmode. The default at startup is now an aspect ratio-preserving windowed mode. Simply press the 'f' key at any time to cycle through them. This was mostly done in sars to provide a source-available test for reproducing a fullscreen SDL2 bug I filed @ https://github.com/libsdl-org/SDL/issues/5139 Otherwise it's pretty silly to bother with doing anything on sars... but it is a handy little mule for such things. --- src/sars.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/sars.h') diff --git a/src/sars.h b/src/sars.h index 39675e5..734e016 100644 --- a/src/sars.h +++ b/src/sars.h @@ -30,12 +30,21 @@ typedef enum sars_context_t { SARS_CONTEXT_CNT } sars_context_t; +typedef enum sars_winmode_t { + SARS_WINMODE_WINDOW, /* windowed in the ideal aspect ratio (may be letterboxed if resized or --window WxH) */ + SARS_WINMODE_FULLSCREEN, /* fullscreened, in the ideal aspect ratio (likely letterboxed) */ + SARS_WINMODE_FILLSCREEN, /* fullscreened, in the screen's aspect ratio (likely stretched) */ + SARS_WINMODE_CNT +} sars_winmode_t; + typedef struct sars_t { SDL_Window *window; SDL_GLContext *gl; stage_t *stage; unsigned window_width, window_height; - unsigned windowed:1; + sars_winmode_t winmode; + + m4f_t projection_x; } sars_t; void sars_canvas_size(sars_t *sars, int *res_width, int *res_height); @@ -45,8 +54,8 @@ void sars_viewport_size(sars_t *sars, int *res_width, int *res_height); void sars_viewport_to_ndc(sars_t *sars, int x, int y, float *res_x, float *res_y); void sars_viewport_from_ndc(sars_t *sars, float x, float y, int *res_x, int *res_y); uint32_t sars_viewport_id(sars_t *sars); -void sars_toggle_fullscreen(sars_t *sars); void sars_render(play_t *play, void *context); void sars_dispatch(play_t *play, void *context, SDL_Event *event); +sars_winmode_t sars_winmode_set(sars_t *sars, sars_winmode_t winmode); #endif -- cgit v1.2.3