diff options
Diffstat (limited to 'themes/WebglContext.cpp')
-rw-r--r-- | themes/WebglContext.cpp | 18 |
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() { |