diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | index.css | 6 | ||||
-rw-r--r-- | index.html | 1 | ||||
-rw-r--r-- | themes/Renderer2d.cpp | 5 | ||||
-rw-r--r-- | themes/Snowflake.cpp | 26 | ||||
-rw-r--r-- | themes/Snowflake.h | 36 | ||||
-rwxr-xr-x | themes/dist/output.wasm | bin | 65641 -> 66787 bytes | |||
-rw-r--r-- | themes/main.cpp | 44 |
8 files changed, 114 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4e5f6c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~
\ No newline at end of file @@ -184,7 +184,7 @@ input:focus { /* Theme display */ #theme_container { - position: absolute; + position: fixed; top: 0; left: 0; width: 100vw; @@ -239,6 +239,10 @@ input:focus { background-color: orange; } +#theme_selector > #theme_button_winter { + background-color: #79C0D7; +} + /* Phone screen adjustments */ @media only screen and (device-width: 1280px), only screen and (max-width:1280px) { @@ -72,6 +72,7 @@ <div id="theme_selector" class="hidden"> <button id="theme_button_default">Default</button> <button id="theme_button_autumn">Autumn</button> + <button id="theme_button_winter">Winter</button> </div> </body> diff --git a/themes/Renderer2d.cpp b/themes/Renderer2d.cpp index 2750557..a58ad86 100644 --- a/themes/Renderer2d.cpp +++ b/themes/Renderer2d.cpp @@ -27,12 +27,11 @@ const char* renderer2dFragmentShader = EM_BOOL onScreenSizeChanged(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) { Renderer2d* renderer = (Renderer2d*)userData; - renderer->context->width = uiEvent->documentBodyClientWidth; - renderer->context->height = uiEvent->documentBodyClientHeight; - EMSCRIPTEN_RESULT result = emscripten_set_canvas_element_size( renderer->context->query, renderer->context->width, renderer->context->height); + 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; } diff --git a/themes/Snowflake.cpp b/themes/Snowflake.cpp new file mode 100644 index 0000000..54654f0 --- /dev/null +++ b/themes/Snowflake.cpp @@ -0,0 +1,26 @@ +#include "Snowflake.h" + +void SnowflakeParticleRenderer::load(SnowflakeLoadParameters params, Renderer2d* renderer) { + updateData = new SnowflakeUpdateData[maxSnowflakes]; + renderData = new SnowflakeRenderData[maxSnowflakes]; + activeIndex = 0; + + for (int32 s = 0; s < maxSnowflakes; s++) { + auto ud = &updateData[s]; + auto rd = &renderData[s]; + + ud->velocity = params->flakeV0; + } +} + +void SnowflakeParticleRenderer::update(float32 dtSeconds) { + +} + +void SnowflakeParticleRenderer::render(Renderer2d* renderer) { + +} + +void SnowflakeParticleRenderer::unload() { + +} diff --git a/themes/Snowflake.h b/themes/Snowflake.h new file mode 100644 index 0000000..09b05db --- /dev/null +++ b/themes/Snowflake.h @@ -0,0 +1,36 @@ +#include "types.h" +#include "mathlib.h" + +struct Renderer2d; +struct SnowflakeUpdateData; +struct SnowflakeRenderData; + +struct SnowflakeLoadParameters { + int32 maxSnowflakes = 10000; + float32 rateOfSnowfall = 0.1f; + Vector3 flakeV0 = { 0, 1, 0 }; + float32 flakeSize = 5.f; + float32 flakeSizeDeviation = 1.f; + Vector4 snowColor = { 0.8, 0.8, 0.8, 1.0 }; +}; + +struct SnowflakeParticleRenderer { + int32 activeIndex = 0; + Vector3 windSpeed = { 0, 0, 0 }; + SnowflakeUpdateData* updateData; + SnowflakeRenderData* renderData; + + void load(SnowflakeLoadParameters params, Renderer2d* renderer);o + void update(float32 dtSeconds); + void render(Renderer2d* renderer); + void unload(); +}; + +struct SnowflakeUpdateData { + Vector3 velocity; + Vector3 position; +}; + +struct SnowflakeRenderData { + +}; diff --git a/themes/dist/output.wasm b/themes/dist/output.wasm Binary files differindex 329cc80..495ea67 100755 --- a/themes/dist/output.wasm +++ b/themes/dist/output.wasm diff --git a/themes/main.cpp b/themes/main.cpp index 2d63e00..8ca7fc4 100644 --- a/themes/main.cpp +++ b/themes/main.cpp @@ -8,7 +8,8 @@ enum Theme { Default = 0, - Autumn + Autumn, + Winter }; struct AutumnTheme { @@ -21,22 +22,32 @@ struct AutumnTheme { void unload(); }; +struct WinterTheme { + void load(Renderer2d* renderer); + void update(float32 dtSeconds); + void render(Renderer2d* renderer); + void unload(); +}; + void load(Theme theme); void unload(); void update(float32 dtSeconds, void* userData); EM_BOOL selectNone(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); EM_BOOL selectAutumn(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); +EM_BOOL selectWinter(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); WebglContext context; Renderer2d renderer; MainLoop mainLoop; Theme activeTheme = Theme::Default; AutumnTheme autumnTheme; +WinterTheme winterTheme; int main() { context.init("#theme_canvas"); emscripten_set_click_callback("#theme_button_default", NULL, false, selectNone); emscripten_set_click_callback("#theme_button_autumn", NULL, false, selectAutumn); + emscripten_set_click_callback("#theme_button_winter", NULL, false, selectWinter); return 0; } @@ -58,6 +69,9 @@ void load(Theme theme) { case Theme::Autumn: autumnTheme.load(&renderer); break; + case Theme::Winter: + winterTheme.load(&renderer); + break; default: break; } @@ -69,6 +83,9 @@ void update(float32 dtSeconds, void* userData) { case Theme::Autumn: autumnTheme.update(dtSeconds); break; + case Theme::Winter: + winterTheme.update(dtSeconds); + break; default: break; } @@ -79,6 +96,9 @@ void update(float32 dtSeconds, void* userData) { case Theme::Autumn: autumnTheme.render(&renderer); break; + case Theme::Winter: + winterTheme.render(&renderer); + break; default: break; } @@ -89,6 +109,9 @@ void unload() { case Theme::Autumn: autumnTheme.unload(); break; + case Theme::Winter: + winterTheme.unload(); + break; default: break; } @@ -113,6 +136,12 @@ EM_BOOL selectAutumn(int eventType, const EmscriptenMouseEvent* mouseEvent, void return true; } +EM_BOOL selectWinter(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { + printf("Winter theme selected\n"); + load(Theme::Winter); + return true; +} + // -- Autumn theme void AutumnTheme::load(Renderer2d* renderer) { renderer->clearColor = Vector4(252, 210, 153, 255).toNormalizedColor(); @@ -135,3 +164,16 @@ void AutumnTheme::unload() { leafParticles.unload(); } +// -- Winter theme +void WinterTheme::load(Renderer2d* renderer) { + renderer->clearColor = Vector4(200, 229, 239, 255).toNormalizedColor(); +} + +void WinterTheme::update(float32 dtSeconds) { +} + +void WinterTheme::render(Renderer2d* renderer) { +} + +void WinterTheme::unload() { +} |