Skip to content

Commit

Permalink
fix: respect screen DPI
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Feb 26, 2024
1 parent a71e743 commit 7d577cc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions raylib.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ class RaylibJs {
}

InitWindow(width, height, title_ptr) {
this.ctx.canvas.width = width;
this.ctx.canvas.height = height;
// Adjust viewport size according to screen DPI for HiDPI screens.
// see: https://web.dev/articles/canvas-hidipi
const dpi = window.devicePixelRatio || 1;

const { canvas } = this.ctx;
canvas.height = height * dpi;
canvas.width = width * dpi;
canvas.style.height = `${height}px`;
canvas.style.width = `${width}px`;
this.ctx.scale(dpi, dpi);

const buffer = this.wasm.instance.exports.memory.buffer;
document.title = cstr_by_ptr(buffer, title_ptr);
}
Expand Down

0 comments on commit 7d577cc

Please sign in to comment.