diff options
author | mattkae <mattkae@protonmail.com> | 2022-05-01 21:55:18 -0400 |
---|---|---|
committer | mattkae <mattkae@protonmail.com> | 2022-05-01 21:55:18 -0400 |
commit | 1c051dffdb27ff6ebaa96802b021e99e49afb861 (patch) | |
tree | 915dca8be4507da86c1f19726560a88b568ab280 | |
parent | 40a924db3664318615a9a3f11ee25c206cb77fe1 (diff) |
Fixed resize issue
-rw-r--r-- | themes/Renderer2d.cpp | 16 | ||||
-rw-r--r-- | themes/Renderer3d.cpp | 8 | ||||
-rw-r--r-- | themes/Snowflake.cpp | 2 | ||||
-rw-r--r-- | themes/WebglContext.cpp | 18 | ||||
-rw-r--r-- | themes/WebglContext.h | 4 | ||||
-rwxr-xr-x | 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<f32>(renderer->context->width); yMax = static_cast<f32>(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 <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() { 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 Binary files differindex 1c12a60..b8a0e67 100755 --- a/themes/dist/output.wasm +++ b/themes/dist/output.wasm |