summaryrefslogtreecommitdiff
path: root/source/saw/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/saw/main.c')
-rw-r--r--source/saw/main.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/source/saw/main.c b/source/saw/main.c
new file mode 100644
index 0000000..691307a
--- /dev/null
+++ b/source/saw/main.c
@@ -0,0 +1,83 @@
+// TODO
+// - Always use OpenGL ES in both sokol and nanovg.
+// - Custom OpenGL loader.
+//
+
+#ifdef __EMSCRIPTEN__
+# define SOKOL_GLES3
+# define NANOVG_GLES3 1
+#else
+# define SOKOL_GLCORE33
+# define NANOVG_GL3 1
+#endif
+
+#include "../kit/time.h" // for timespec_get
+
+// sokol
+#define SOKOL_APP_IMPL
+#include "../thirdparty/sokol_app.h"
+
+// nanovg
+#include "../thirdparty/nanovg.c"
+#include "../thirdparty/nanovg_gl.c"
+#include "../thirdparty/android.c"
+
+// miniaudio
+#define MINIAUDIO_IMPLEMENTATION
+#include "../thirdparty/miniaudio.h"
+
+static struct NVGcontext *saw_nvg;
+
+static void saw_init(void) {
+#ifdef SOKOL_GLCORE33
+ saw_nvg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
+#else
+ saw_nvg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
+#endif
+}
+
+static void saw_frame(void) {
+ int width = sapp_width();
+ int height = sapp_height();
+
+ glViewport(0, 0, width, height);
+ glClearColor(.3f, .2f, .4f, 1.f);
+ glClearDepthf(1.f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
+ GL_STENCIL_BUFFER_BIT);
+
+ nvgBeginFrame(saw_nvg, width, height, sapp_dpi_scale());
+
+ nvgBeginPath(saw_nvg);
+ nvgRect(saw_nvg, 100, 100, 300, 200);
+ nvgFillColor(saw_nvg, nvgRGBA(255, 192, 0, 255));
+ nvgFill(saw_nvg);
+
+ nvgEndFrame(saw_nvg);
+}
+
+static void saw_cleanup(void) {
+#ifdef SOKOL_GLCORE33
+ nvgDeleteGL3(saw_nvg);
+#else
+ nvgDeleteGLES3(saw_nvg);
+#endif
+}
+
+static void saw_event(sapp_event const *event) { }
+
+char const *__lsan_default_suppressions() {
+ // There is leaks in NVidia driver on Linux.
+ return "leak:nvidia";
+}
+
+sapp_desc sokol_main(int argc, char **argv) {
+ return (sapp_desc) {
+ .width = 1280,
+ .height = 720,
+ .init_cb = saw_init,
+ .frame_cb = saw_frame,
+ .cleanup_cb = saw_cleanup,
+ .event_cb = saw_event,
+ };
+}