From 1c051dffdb27ff6ebaa96802b021e99e49afb861 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 1 May 2022 21:55:18 -0400 Subject: Fixed resize issue --- themes/Renderer2d.cpp | 16 ++-------------- themes/Renderer3d.cpp | 8 ++++++++ themes/Snowflake.cpp | 2 +- themes/WebglContext.cpp | 18 ++++++++++++++++-- themes/WebglContext.h | 4 ++-- themes/dist/output.wasm | Bin 89344 -> 89301 bytes 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/themes/Renderer2d.cpp b/themes/Renderer2d.cpp index 0d4eca2..dacebe3 100644 --- a/themes/Renderer2d.cpp +++ b/themes/Renderer2d.cpp @@ -25,18 +25,6 @@ const char* renderer2dFragmentShader = " gl_FragColor = VertexColor; \n" "}"; -EM_BOOL onScreenSizeChanged(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) { - Renderer2d* renderer = (Renderer2d*)userData; - - EMSCRIPTEN_RESULT result = emscripten_set_canvas_element_size( renderer->context->query, uiEvent->documentBodyClientWidth, uiEvent->documentBodyClientHeight); - if (result != EMSCRIPTEN_RESULT_SUCCESS) { - printf("Failed to resize element at query: %s\n", renderer->context->query); - } - renderer->projection = Mat4x4().getOrthographicMatrix(0, renderer->context->width, 0, renderer->context->height); - - return true; -} - void Renderer2d::load(WebglContext* inContext) { context = inContext; printf("Compiling Renderer2d shader...\n"); @@ -51,11 +39,11 @@ void Renderer2d::load(WebglContext* inContext) { projection = Mat4x4().getOrthographicMatrix(0, context->width, 0, context->height); printf("Renderer2d shader compiled.\n"); - - emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, onScreenSizeChanged); } void Renderer2d::render() { + projection = Mat4x4().getOrthographicMatrix(0, context->width, 0, context->height); + glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); diff --git a/themes/Renderer3d.cpp b/themes/Renderer3d.cpp index 0106f10..ded364d 100644 --- a/themes/Renderer3d.cpp +++ b/themes/Renderer3d.cpp @@ -71,3 +71,11 @@ void Renderer3D::unload() { glClear(GL_COLOR_BUFFER_BIT); glDeleteProgram(shader); } + +Mesh3d Mesh3d_fromObj(std::string content) { + Mesh3d result; + + + + return result; +} \ No newline at end of file diff --git a/themes/Snowflake.cpp b/themes/Snowflake.cpp index 1e1e648..9a8abde 100644 --- a/themes/Snowflake.cpp +++ b/themes/Snowflake.cpp @@ -65,7 +65,7 @@ void SnowflakeParticleRenderer::load(SnowflakeLoadParameters params, Renderer2d* xMax = static_cast(renderer->context->width); yMax = static_cast(renderer->context->height); - + // Initialize each snow flake with its shape for (i32 s = 0; s < numSnowflakes; s++) { auto ud = &updateData[s]; 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 +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(inWidth); + context->height = static_cast(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(inWidth); - height = static_cast(inHeight); + width = static_cast(inWidth); + height = static_cast(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() { diff --git a/themes/WebglContext.h b/themes/WebglContext.h index 7b3cc1c..1956092 100644 --- a/themes/WebglContext.h +++ b/themes/WebglContext.h @@ -8,8 +8,8 @@ struct WebglContext { EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context; - i32 width = 800; - i32 height = 600; + f32 width = 800; + f32 height = 600; char query[128];; void init(const char* inQuery); diff --git a/themes/dist/output.wasm b/themes/dist/output.wasm index 1c12a60..b8a0e67 100755 Binary files a/themes/dist/output.wasm and b/themes/dist/output.wasm differ -- cgit v1.2.1