Skip to content

[rcore] Make GetWindowScaleDPI() consistent on all backends - #6402

Merged
raysan5 merged 5 commits into
raysan5:masterfrom
Ne0nWinds:window-scale-dpi-backend
Nov 13, 2026
Merged

raysan5 merged 5 commits into
raysan5:masterfrom
Ne0nWinds:window-scale-dpi-backend

Conversation

@Ne0nWinds

@Ne0nWinds Ne0nWinds commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

GLFW return 1.0 when FLAG_WINDOW_HIGHDPI is not set, while all other backends return the actual window DPI.

This PR makes GLFW match the other backends.

Many places in rcore relied on the old behavior of GLFW. They've been updated too

Related PRs:
#6372: Bug in various examples with GetWindowScaleDPI()
#6352: Win32 HighDPI Support, where I first noticed this issue

@raysan5

raysan5 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@Ne0nWinds I'm checking this PR and thinking if this is the best/right approach for the user. The idea behind returning 1.0f for screen scaling matching logical-physical units was for convenience for the user if no HighDPI was enabled (and managed internally)... but now I think about the possibility of user deciding to manage HighDPI on their side; in that case it would have no way to get the current display scaling DPI factor.

What do you think?

@Ne0nWinds

Copy link
Copy Markdown
Contributor Author

@raysan5 Yeah, I think it'd much better if GetWindowScaleDPIalways returned the current window DPI, regardless of what flags are set.

That allows the user to have much more control. If they want the existing GLFW behavior, they can always manually check the window state themselves like this:

float GetDPIScale() {
  float scale = 1.0f;
  if (!IsWindowFullscreen() && IsWindowState(FLAG_WINDOW_HIGHDPI))
  {
    scale = GetWindowDPIScale().x;
  }
  return scale;
}

I think it's probably better to just let the user decide how they want to handle high-dpi scaling when FLAG_WINDOW_HIGHDPI isn't set.

Maybe we could even make a small example for how to have custom logic for high-dpi, too.

For this PR, I could remove all the changes to other backends and only change GLFW backend to match all the others.

@raysan5

raysan5 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@Ne0nWinds Ok, let's return the current scale DPI so user can manage it at user side if desired.

Maybe we could even make a small example for how to have custom logic for high-dpi, too.

Definitely a usage example could be useful.

For this PR, I could remove all the changes to other backends and only change GLFW backend to match all the others.

Ok, leet's do it. Note that GLFW backend was assuming a 1.0f scaling DPI for FLAG_WINDOW_HIGHDPI not set and some functions could multiply by that return value based on that design decision. It should be reviewed.

@Ne0nWinds Ne0nWinds changed the title [rcore] Make GetWindowScaleDPI() consistent on all desktop and web backends [rcore] Make GetWindowScaleDPI() consistent on all backends Nov 12, 2026
Comment thread src/rcore.c Resolved
Comment thread src/rcore.c
{
Vector2 scale = GetWindowScaleDPI();
Vector2 scale = { 1.0f, 1.0f };
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && !FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) scale = GetWindowScaleDPI();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an apple device to test this, but this shouldn't change the behavior

@Ne0nWinds

Ne0nWinds commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

One note: it looks like the scissor rendering mode on RGFW is broken when both fullscreen and high-dpi are enabled.

Minimal repro:

int main(void)
{
    SetConfigFlags(FLAG_WINDOW_HIGHDPI);
    InitWindow(800, 450, "scissor");

    while (!WindowShouldClose())
    {
        // issue only happens in fullscreen
        if (IsKeyPressed(KEY_F)) ToggleFullscreen();

        BeginDrawing();
            ClearBackground(DARKBLUE);
            BeginScissorMode(100, 100, 200, 100);
                ClearBackground(RED);
            EndScissorMode();
            
            // draw where the red scissored rectangle should appear
            DrawRectangleLines(100, 100, 200, 100, GREEN);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}

It's wrong both before and after my PR (if you compare with GLFW). I changed the scissor logic, which changes how this example behaves, but it's still wrong. That would be best to fix in a separate PR because I think it's something specific to RGFW.

The fullscreen scissor logic is unchanged for GLFW after this PR.

@Ne0nWinds

Copy link
Copy Markdown
Contributor Author

Android scissor is also wrong. It looks like it's better after this PR, but still wrong

while (!WindowShouldClose())
{
    BeginDrawing();
        ClearBackground(DARKBLUE);
        BeginScissorMode(100, 100, 200, 100);
            ClearBackground(RED);
        EndScissorMode();

        // where the red scissored drawing should be
        DrawRectangleLines(100, 100, 200, 100, GREEN);
    EndDrawing();
}
Before After
before after

@Ne0nWinds

Ne0nWinds commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

For reference, here is GLFW (both before and after this PR) running the same code above. It works correctly with both fullscreen and high-dpi enabled:

image

The red square fits inside the green rectangle

@raysan5
raysan5 merged commit cfcfb2b into raysan5:master Nov 13, 2026
16 checks passed
@raysan5

raysan5 commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@Ne0nWinds Thanks for the full review. I'm testing on macOS later today. About Android, it's been a while I didn't work with that platform, maybe @Bigfoot71 can help on that regards (if not too busy). I will also try to setup an Android env for testing.

@Ne0nWinds
Ne0nWinds deleted the window-scale-dpi-backend branch November 13, 2026 14:46
@raysan5

raysan5 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

@Ne0nWinds tested on macBook Air M4 laptop, it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants