We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a71e743 commit 7d577ccCopy full SHA for 7d577cc
raylib.js
@@ -107,8 +107,17 @@ class RaylibJs {
107
}
108
109
InitWindow(width, height, title_ptr) {
110
- this.ctx.canvas.width = width;
111
- this.ctx.canvas.height = height;
+ // Adjust viewport size according to screen DPI for HiDPI screens.
+ // see: https://web.dev/articles/canvas-hidipi
112
+ const dpi = window.devicePixelRatio || 1;
113
+
114
+ const { canvas } = this.ctx;
115
+ canvas.height = height * dpi;
116
+ canvas.width = width * dpi;
117
+ canvas.style.height = `${height}px`;
118
+ canvas.style.width = `${width}px`;
119
+ this.ctx.scale(dpi, dpi);
120
121
const buffer = this.wasm.instance.exports.memory.buffer;
122
document.title = cstr_by_ptr(buffer, title_ptr);
123
0 commit comments