Skip to content

Commit

Permalink
Add necessary code to get emscripten rendering to a web browser screen
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jul 4, 2024
1 parent e61dad1 commit f3121e2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/hellotriangle/hellotriangle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <oscar/oscar.h>

#ifdef EMSCRIPTEN
#include <emscripten.h>
#include <emscripten/html5.h>
#endif

using namespace osc;

namespace
Expand Down Expand Up @@ -32,12 +37,24 @@ namespace
};
}


int main(int, char**)
{
#ifdef EMSCRIPTEN
osc::App* app = new osc::App{};
app->setup_main_loop<HelloTriangleScreen>();
emscripten_request_animation_frame_loop([](double, void* ptr) -> int
{
const bool keep_running = static_cast<App*>(ptr)->do_main_loop_step();
return keep_running ? EM_TRUE : EM_FALSE;
}, app);
return 0;
#else
osc::App app;
app.setup_main_loop<HelloTriangleScreen>();
ScopeGuard guard{[&app](){ app.teardown_main_loop(); }};
while (app.do_main_loop_step()) {
}
return 0;
#endif
}

0 comments on commit f3121e2

Please sign in to comment.