From 0b8596a5ebec39f797fe8a14eed1bda3c2e3a93d Mon Sep 17 00:00:00 2001 From: mattkae Date: Sat, 7 May 2022 12:17:36 -0400 Subject: Working bunny render --- themes/main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'themes/main.cpp') diff --git a/themes/main.cpp b/themes/main.cpp index d3966af..ef7d18b 100644 --- a/themes/main.cpp +++ b/themes/main.cpp @@ -37,6 +37,9 @@ struct WinterTheme { }; struct SpringTheme { + bool canRenderBunny = false; + Mesh3d bunnyMesh; + void load(Renderer3D* renderer); void update(f32 dtSeconds); void render(Renderer3D* renderer); @@ -227,17 +230,21 @@ void WinterTheme::unload() { // -- Spring theme void onBunnySuccess(emscripten_fetch_t *fetch) { - printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url); - // The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1]; - emscripten_fetch_close(fetch); // Free data associated with the fetch. + springTheme.canRenderBunny = true; + printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url); + const i32 len = fetch->numBytes; + springTheme.bunnyMesh = Mesh3d_fromObj(&renderer3d, fetch->data, len); + // The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1]; + emscripten_fetch_close(fetch); // Free data associated with the fetch. } void onBunnyFail(emscripten_fetch_t *fetch) { - printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status); - emscripten_fetch_close(fetch); // Also free data on failure. + printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status); + emscripten_fetch_close(fetch); // Also free data on failure. } void SpringTheme::load(Renderer3D* renderer) { + canRenderBunny = false; renderer->clearColor = Vector4(160, 231, 160, 255.f).toNormalizedColor(); emscripten_fetch_attr_t attr; @@ -253,7 +260,12 @@ void SpringTheme::update(f32 dtSeconds) { } void SpringTheme::render(Renderer3D* renderer) { + renderer->render(); + if (canRenderBunny) { + bunnyMesh.render(renderer); + } } void SpringTheme::unload() { -} \ No newline at end of file + bunnyMesh.unload(); +} -- cgit v1.2.1