summaryrefslogtreecommitdiff
path: root/themes/WebglContext.cpp
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-05-01 21:55:18 -0400
committermattkae <mattkae@protonmail.com>2022-05-01 21:55:18 -0400
commit1c051dffdb27ff6ebaa96802b021e99e49afb861 (patch)
tree915dca8be4507da86c1f19726560a88b568ab280 /themes/WebglContext.cpp
parent40a924db3664318615a9a3f11ee25c206cb77fe1 (diff)
Fixed resize issue
Diffstat (limited to 'themes/WebglContext.cpp')
-rw-r--r--themes/WebglContext.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/themes/WebglContext.cpp b/themes/WebglContext.cpp
index 0f2e2d3..df49c2d 100644
--- a/themes/WebglContext.cpp
+++ b/themes/WebglContext.cpp
@@ -2,12 +2,24 @@
#include <cstdio>
+EM_BOOL onResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) {
+ WebglContext* context = (WebglContext*)userData;
+
+ f64 inWidth, inHeight;
+ emscripten_get_element_css_size(context->query, &inWidth, &inHeight);
+
+ context->width = static_cast<f32>(inWidth);
+ context->height = static_cast<f32>(inHeight);
+
+ return true;
+}
+
void WebglContext::init(const char* inQuery) {
strcpy(query, inQuery);
f64 inWidth, inHeight;
emscripten_get_element_css_size(query, &inWidth, &inHeight);
- width = static_cast<i32>(inWidth);
- height = static_cast<i32>(inHeight);
+ width = static_cast<f32>(inWidth);
+ height = static_cast<f32>(inHeight);
emscripten_set_canvas_element_size( query, width, height);
EmscriptenWebGLContextAttributes attrs;
@@ -21,6 +33,8 @@ void WebglContext::init(const char* inQuery) {
makeCurrentContext();
glClearColor(0, 0, 0, 0.0f);
+
+ emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, onResize);
};
void WebglContext::makeCurrentContext() {