Skip to content

Commit 685b17a

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
Emscripten: Added full screen canvas (close #127)
1 parent 2a15a9b commit 685b17a

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

SampleBase/src/Emscripten/InputControllerEmscripten.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,15 +23,18 @@
2323
*/
2424

2525
#include <emscripten/key_codes.h>
26+
#include <emscripten/emscripten.h>
2627
#include "InputController.hpp"
2728

2829
namespace Diligent
2930
{
3031

3132
void InputControllerEmscripten::OnMouseMove(int32_t MouseX, int32_t MouseY)
3233
{
33-
m_MouseState.PosX = static_cast<float>(MouseX);
34-
m_MouseState.PosY = static_cast<float>(MouseY);
34+
auto DevicePixelRatio = emscripten_get_device_pixel_ratio();
35+
36+
m_MouseState.PosX = DevicePixelRatio * static_cast<float>(MouseX);
37+
m_MouseState.PosY = DevicePixelRatio * static_cast<float>(MouseY);
3538
}
3639

3740
void InputControllerEmscripten::OnMouseButtonEvent(MouseButton Button, bool IsPressed)

SampleBase/src/Emscripten/resources/emscripten_template.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212

1313
.emscripten {
1414
position: absolute;
15-
top: 0;
16-
bottom: 0;
17-
left: 0;
18-
right: 0;
19-
padding: 0;
20-
margin: auto;
21-
width: 1280;
22-
height: 720;
15+
top: 0px;
16+
left: 0px;
17+
margin: 0px;
18+
border: 0;
19+
width: 100%;
20+
height: 100%;
2321
overflow: hidden;
2422
display: block;
2523
image-rendering: optimizeSpeed;
@@ -50,9 +48,14 @@
5048
console.error(text);
5149
},
5250
canvas: (function () {
51+
var dpr = window.devicePixelRatio;
5352
var canvas = document.getElementById('canvas');
54-
canvas.width = 1280;
55-
canvas.height = 720;
53+
canvas.width = Math.ceil(dpr * window.innerWidth);
54+
canvas.height = Math.ceil(dpr * window.innerHeight);
55+
window.addEventListener("resize", function () {
56+
canvas.width = Math.ceil(dpr * window.innerWidth);
57+
canvas.height = Math.ceil(dpr * window.innerHeight);
58+
});
5659
canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
5760
return canvas;
5861
})(),

0 commit comments

Comments
 (0)