SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Emscripten - incorrect mouse position reported with HIDPI and scaling

Open mausimus opened this issue 1 year ago • 0 comments

When creating a window with SDL_WINDOW_HIGH_PIXEL_DENSITY (for pixel perfect rendering), position returned by SDL_GetMouseState() is incorrectly scaled under Emscripten.

Windows 11 w/ 125% scale Chrome 131, Firefox 133 Emscripten 3.1.73 (latest) SDL 3.1.7 (latest)

Minimal example (dot is off the cursor):

    SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, SDL_WINDOW_HIGH_PIXEL_DENSITY, &window, &renderer);
    ...
    float mx,my;
    SDL_GetMouseState(&mx, &my);
    SDL_SetRenderDrawColorFloat(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE_FLOAT);
    SDL_FRect mr;
    mr.x = mx - 1;
    mr.y = my - 1;
    mr.w = 3;
    mr.h = 3;
    SDL_RenderFillRect(renderer, &mr);

emmouse.zip

mausimus avatar Dec 09 '24 10:12 mausimus