Skip to content

Commit

Permalink
Re-enables the fullscreen toggle.
Browse files Browse the repository at this point in the history
The rendering in fullscreen is still broken however. The viewports don't
seem to get impacted by the SDL_SetRendererLogicalPresentation state any
longer.
  • Loading branch information
LiquidityC committed Nov 5, 2024
1 parent 726956a commit c504b8b
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ static Sprite *howto_tooltip = NULL;
static Sprite *new_artifact_tooltip = NULL;
static unsigned int cLevel = 1;
static float deltaTime = 1.0;
static float renderScale = 1.0;
static Turn currentTurn = PLAYER;
static class_t playerClass = WARRIOR;
static bool quickGame = false;
Expand Down Expand Up @@ -208,13 +207,6 @@ bool initSDL(void)

Dimension dim = getScreenDimensions();

if (dim.height > 1080) {
info("Hi resolution screen detected (%u x %u)", dim.width, dim.height);
// TODO(Linus): Fixme, this scaling is messing up the rendering
renderScale = 1.0;
info("Scaling by %f", renderScale);
}

debug("Initializing SDL_image");
if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) {
error("Unable to initiate img loading: %s",
Expand Down Expand Up @@ -252,8 +244,8 @@ bool initSDL(void)
char title_buffer[100];
m_sprintf(title_buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE);
gWindow = SDL_CreateWindow(title_buffer,
(int)(SCREEN_WIDTH * renderScale),
(int)(SCREEN_HEIGHT * renderScale), 0);
SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (gWindow == NULL)
{
error("Unable to create window: %s", SDL_GetError());
Expand All @@ -274,7 +266,7 @@ bool initSDL(void)
error("Unable to set blend mode: %s", SDL_GetError());
return false;
}
if (!SDL_SetRenderLogicalPresentation(gRenderer, (int)(SCREEN_WIDTH*renderScale), (int)(SCREEN_HEIGHT*renderScale), SDL_LOGICAL_PRESENTATION_INTEGER_SCALE))
if (!SDL_SetRenderLogicalPresentation(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX))
{
error("Unable to initiate scaling: %s",
SDL_GetError());
Expand All @@ -292,6 +284,8 @@ bool initSDL(void)
static void
initViewports(Uint32 offset)
{
/* FIXME: This does not work with
* SDL_SetRenderLogicalPresentation any longer. Needs looking at. */
mainViewport = (SDL_Rect) { offset, 0,
SCREEN_WIDTH, SCREEN_HEIGHT
};
Expand Down Expand Up @@ -784,28 +778,11 @@ init(void)
static void
toggle_fullscreen(void)
{
bool fullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN;
SDL_WindowFlags flags = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN;
Settings *settings = settings_get();
if (!fullscreen) {
initViewports(0);
SDL_SetWindowFullscreen(gWindow, 0);
settings->fullscreen_enabled = false;
}
else {
int w, h, lw, lh;
SDL_GetRenderLogicalPresentation(gRenderer, &lw, &lh, NULL);
SDL_GetWindowSize(gWindow, &w, &h);

double lratio = (double) w / (double) lw;

SDL_SetWindowFullscreen(gWindow, true);

const SDL_DisplayMode *dMode = SDL_GetWindowFullscreenMode(gWindow);
double ratio = (double) (dMode->w) / w;
double offset = ((dMode->w - w) / 2.0);
initViewports((Uint32)(offset/(ratio*lratio)));
settings->fullscreen_enabled = true;
}
bool fullscreen = flags == SDL_WINDOW_FULLSCREEN;
SDL_SetWindowFullscreen(gWindow, !fullscreen);
settings->fullscreen_enabled = !fullscreen;
}

static void
Expand Down

0 comments on commit c504b8b

Please sign in to comment.