#include "../../../shared_cpp/OrthographicRenderer.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" #include "../../../shared_cpp/MainLoop.h" #include #include #include #include typedef OrthographicShape<3> TriangleShape; EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); EM_BOOL update(float time, void* userData); WebglContext context; OrthographicRenderer renderer; TriangleShape shape; MainLoop mainLoop; int main() { context.init("#gl_canvas"); emscripten_set_click_callback("#gl_canvas_play", NULL, false, onPlayClicked); emscripten_set_click_callback("#gl_canvas_stop", NULL, false, onStopClicked); return 0; } EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { printf("Play clicked\n"); renderer.load(); shape.vertices[0] = { Vector2 { -1, -1 }, Vector4 { 1, 0, 0, 1 } }; shape.vertices[1] = { Vector2 { 0, 1 }, Vector4{ 0, 1, 0, 1 } }; shape.vertices[2] = { Vector2 { 1, -1 }, Vector4 { 0, 0, 1, 1 } }; shape.load(&renderer); mainLoop.run(update); return true; } EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { printf("Stop clicked\n"); mainLoop.stop(); shape.unload(); renderer.unload(); return true; } EM_BOOL update(float deltaTimeSeconds, void* userData) { renderer.render(); shape.render(&renderer); return true; }