diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 88fe2f7..ee4508b 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -16,9 +16,14 @@ #define TEXT_OPT_OPTIONS _("OPTIONS") #define TEXT_OPT_CAMERA _("CAMERA") #define TEXT_OPT_CONTROLS _("CONTROLS") +#define TEXT_OPT_VIDEO _("DISPLAY") #define TEXT_OPT_HIGHLIGHT _("O") #define TEXT_OPT_ANALOGUE _("Analogue Camera") #define TEXT_OPT_MOUSE _("Mouse Look") +#define TEXT_OPT_TEXFILTER _("Texture Filtering") +#define TEXT_OPT_FSCREEN _("Fullscreen") +#define TEXT_OPT_NEAREST _("Nearest") +#define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_UNBOUND _("NONE") #define TEXT_OPT_PRESSKEY _("...") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index a92c800..093c839 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -31,22 +31,23 @@ static u8 optmenu_bind_idx = 0; // menus: add a new submenu definition and a new // option to the optsMain list -static const u8 toggleStr[][64] = { +static const u8 toggleStr[][16] = { { TEXT_OPT_DISABLED }, { TEXT_OPT_ENABLED }, }; -static const u8 menuStr[][64] = { +static const u8 menuStr[][32] = { { TEXT_OPT_HIGHLIGHT }, { TEXT_OPT_BUTTON1 }, { TEXT_OPT_BUTTON2 }, { TEXT_OPT_OPTIONS }, { TEXT_OPT_CAMERA }, { TEXT_OPT_CONTROLS }, + { TEXT_OPT_VIDEO }, { TEXT_EXIT_GAME }, }; -static const u8 optsCameraStr[][64] = { +static const u8 optsCameraStr[][32] = { { TEXT_OPT_CAMX }, { TEXT_OPT_CAMY }, { TEXT_OPT_INVERTX }, @@ -57,7 +58,14 @@ static const u8 optsCameraStr[][64] = { { TEXT_OPT_MOUSE }, }; -static const u8 bindStr[][64] = { +static const u8 optsVideoStr[][32] = { + { TEXT_OPT_FSCREEN }, + { TEXT_OPT_TEXFILTER }, + { TEXT_OPT_NEAREST }, + { TEXT_OPT_LINEAR }, +}; + +static const u8 bindStr[][32] = { { TEXT_OPT_UNBOUND }, { TEXT_OPT_PRESSKEY }, { TEXT_BIND_A }, @@ -76,6 +84,11 @@ static const u8 bindStr[][64] = { { TEXT_BIND_RIGHT }, }; +static const u8 *filterChoices[] = { + optsVideoStr[2], + optsVideoStr[3], +}; + enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -155,6 +168,11 @@ static struct Option optsControls[] = { { .type = OPT_BIND, .label = bindStr[15], .uval = configKeyStickRight, }, }; +static struct Option optsVideo[] = { + { .type = OPT_TOGGLE, .label = optsVideoStr[0], .bval = &configFullscreen, }, + { .type = OPT_CHOICE, .label = optsVideoStr[1], .uval = &configFiltering, .choices = filterChoices, .numChoices = 2 }, +}; + /* submenu definitions */ static struct SubMenu menuCamera = { @@ -169,12 +187,19 @@ static struct SubMenu menuControls = { .numOpts = sizeof(optsControls) / sizeof(optsControls[0]), }; +static struct SubMenu menuVideo = { + .label = menuStr[6], + .opts = optsVideo, + .numOpts = sizeof(optsVideo) / sizeof(optsVideo[0]), +}; + /* main options menu definition */ static struct Option optsMain[] = { { .type = OPT_SUBMENU, .label = menuStr[4], .nextMenu = &menuCamera, }, { .type = OPT_SUBMENU, .label = menuStr[5], .nextMenu = &menuControls, }, - { .type = OPT_BUTTON, .label = menuStr[6], .actionFn = optmenu_act_exit, }, + { .type = OPT_SUBMENU, .label = menuStr[6], .nextMenu = &menuVideo, }, + { .type = OPT_BUTTON, .label = menuStr[7], .actionFn = optmenu_act_exit, }, }; static struct SubMenu menuMain = { @@ -311,7 +336,7 @@ static void optmenu_opt_change(struct Option *opt, s32 val) { break; default: break; - }; + } } static inline s16 get_hudstr_centered_x(const s16 sx, const u8 *str) { diff --git a/src/pc/configfile.c b/src/pc/configfile.c index e4a8869..6730881 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -32,7 +32,8 @@ struct ConfigOption { *Config options and default values */ -bool configFullscreen = false; +bool configFullscreen = false; +unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point // Keyboard mappings (VK_ values, by default keyboard/gamepad/mouse) unsigned int configKeyA[MAX_BINDS] = { 0x0026, 0x1000, 0x1103 }; unsigned int configKeyB[MAX_BINDS] = { 0x0033, 0x1002, 0x1101 }; @@ -64,6 +65,7 @@ unsigned int configSkipIntro = 0; static const struct ConfigOption options[] = { {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, + {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, {.name = "key_b", .type = CONFIG_TYPE_BIND, .uintValue = configKeyB}, {.name = "key_start", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStart}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index c53d699..de277fb 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -7,6 +7,7 @@ #define MAX_BINDS 3 extern bool configFullscreen; +extern unsigned int configFiltering; extern unsigned int configKeyA[]; extern unsigned int configKeyB[]; extern unsigned int configKeyStart[]; diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c index 65b3099..b73462e 100644 --- a/src/pc/gfx/gfx_opengl.c +++ b/src/pc/gfx/gfx_opengl.c @@ -26,6 +26,7 @@ #include "gfx_cc.h" #include "gfx_rendering_api.h" +#include "../configfile.h" struct ShaderProgram { uint32_t shader_id; @@ -408,9 +409,10 @@ static uint32_t gfx_cm_to_opengl(uint32_t val) { } static void gfx_opengl_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) { + const GLenum filter = (linear_filter && (configFiltering == 1)) ? GL_LINEAR : GL_NEAREST; glActiveTexture(GL_TEXTURE0 + tile); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear_filter ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear_filter ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gfx_cm_to_opengl(cms)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gfx_cm_to_opengl(cmt)); } diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 561ac95..e701847 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -26,7 +26,8 @@ static SDL_Window *wnd; static int inverted_scancode_table[512]; -extern bool configFullscreen; +static bool cur_fullscreen; +static uint32_t cur_width, cur_height; const SDL_Scancode windows_scancode_table[] = { @@ -79,20 +80,18 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { {SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN} }; -static void gfx_sdl_set_fullscreen(bool fullscreen) -{ - if (fullscreen) - { +static void gfx_sdl_set_fullscreen(bool fullscreen) { + if (fullscreen == cur_fullscreen) return; + + if (fullscreen) { SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_ShowCursor(SDL_DISABLE); - } - else - { + } else { SDL_SetWindowFullscreen(wnd, 0); SDL_ShowCursor(SDL_ENABLE); } - configFullscreen = fullscreen; + cur_fullscreen = fullscreen; } static void gfx_sdl_init(void) { @@ -190,13 +189,9 @@ static void gfx_sdl_onkeydown(int scancode) { const Uint8 *state = SDL_GetKeyboardState(NULL); if (state[SDL_SCANCODE_LALT] && state[SDL_SCANCODE_RETURN]) - { - gfx_sdl_set_fullscreen(!configFullscreen); - } + configFullscreen = !configFullscreen; else if (state[SDL_SCANCODE_ESCAPE] && configFullscreen) - { - gfx_sdl_set_fullscreen(false); - } + configFullscreen = false; } static void gfx_sdl_onkeyup(int scancode) { @@ -220,6 +215,9 @@ static void gfx_sdl_handle_events(void) { exit(0); } } + // just check if the fullscreen value has changed and toggle fullscreen if it has + if (configFullscreen != cur_fullscreen) + gfx_sdl_set_fullscreen(configFullscreen); } static bool gfx_sdl_start_frame(void) {