Skip to content

Commit 1a1f81d

Browse files
committed
Fixed input box size
1 parent e44ff08 commit 1a1f81d

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
align-items: center;
1818
}
1919
canvas {
20-
width: 100vw;
21-
height: 100vh;
20+
width: 100vw !important;
21+
height: 100vh !important;
2222
display: block;
2323
outline: none;
2424
touch-action: none;
25+
image-rendering: pixelated;
2526
}
2627
#loading-overlay {
2728
position: absolute;
@@ -66,6 +67,11 @@ <h2>Loading...</h2>
6667

6768
var Module = {
6869
canvas: canvas,
70+
setCanvasSize: function(width, height, noRepaint) {
71+
const dpr = window.devicePixelRatio || 1;
72+
this.canvas.width = width * dpr;
73+
this.canvas.height = height * dpr;
74+
},
6975
onRuntimeInitialized: function() {
7076
document.getElementById('loading-overlay').style.display = 'none';
7177
}

src/interactions/interactions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ EM_BOOL browser_resize_callback(int event_type, const EmscriptenUiEvent* ui_even
9494

9595
emscripten_set_canvas_element_size("#canvas", width * ratio, height * ratio);
9696

97-
glfwSetWindowSize(window, static_cast<int>(width), static_cast<int>(height));
97+
int phys_width = static_cast<int>(width * ratio);
98+
int phys_height = static_cast<int>(height * ratio);
99+
glfwSetWindowSize(window, phys_width, phys_height);
98100
return EM_TRUE;
99101
}
100102
#endif

src/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
using vec2 = glm::vec2;
3232

33-
constexpr float WIDTH = 800.00f * 1.5f;
34-
constexpr float HEIGHT = 600.00f * 1.5f;
33+
constexpr float WIDTH = 800.00f * 2.0f;
34+
constexpr float HEIGHT = WIDTH * 3/4;
3535

3636
float last_x = WIDTH / 2.0f;
3737
float last_y = HEIGHT / 2.0f;
@@ -116,7 +116,7 @@ void main_loop_step(AppContext* ctx) {
116116
}
117117

118118
if (ctx->function_state->is_3d) {
119-
glm::mat4 projection = glm::perspective(glm::radians(45.0f), WIDTH / HEIGHT, 0.1f, 100.0f);
119+
glm::mat4 projection = glm::perspective(glm::radians(45.0f), ctx->view_state->width / ctx->view_state->height, 0.1f, 100.0f);
120120
glm::mat4 view = get_view_matrix(camera_state);
121121
glm::mat4 model = glm::mat4(1.0f);
122122
current_shader->setMat4("projection", projection);
@@ -273,6 +273,8 @@ int main() {
273273

274274

275275
#ifdef __EMSCRIPTEN__
276+
//glViewport(0, 0, (int)view_state.width, (int)view_state.height);
277+
emscripten_set_canvas_element_size("#canvas", (int)view_state.width, (int)view_state.height);
276278
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, window, EM_FALSE, browser_resize_callback);
277279
EmscriptenUiEvent fake_event;
278280
fake_event.windowInnerWidth = EM_ASM_INT({ return window.innerWidth; });

0 commit comments

Comments
 (0)