clay icon indicating copy to clipboard operation
clay copied to clipboard

SDL3 High DPI?

Open nilssauer-bit opened this issue 3 months ago • 3 comments

Hi, my SDL3 application using Clay (based on SDL3 example in repo) is not able to scale properly. On my high DPI display, it is really tiny. How do I tell Clay/SDL3 to respect DPI?

nilssauer-bit avatar Sep 15 '25 07:09 nilssauer-bit

It could be because of your text scaling. The text in SDL is scaled in pixels, not relative to the window size. To fix this, just multiply your .fontSize with a scale that respects your window size. I have a function for that:

float getFontScale() {
    int h = 0;
    SDL_GetWindowSize(sdlWindow, NULL, &h);
    return h / BASE_WINDOW_HEIGHT;
}

You can use it like this: .fontSize = 30 * getFontScale(). BASE_WINDOW_HEIGHT is the window height in pixels for which your application is made and looks good at. So your application has the right size at 1600x900, BASE_WINDOW_HEIGHT would be 900.

nobschulth avatar Sep 22 '25 15:09 nobschulth

@nobschulth That is a very helpful function, but it would be more clear if h wasn't initialized. Initializing a variable makes it seem you want to use the value you gave it, but if you're just overwriting it in the next line, you can save a write by simply leaving the value blank.

As always, shoutout to using out-params instead of just returning so that one can't use the function as an rvalue.

cD1rtX3 avatar Sep 23 '25 02:09 cD1rtX3

any way to auto change inside clay?

zeroxer avatar Oct 01 '25 18:10 zeroxer