summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-14 00:53:26 -0600
committersanine <sanine.not@pm.me>2023-02-14 00:53:26 -0600
commitcb9764cddf0ed8186e78c418f066b31921fbda40 (patch)
tree80f58cead45f4f855e910ac4cdb5aaf461797daf /src
parentf1fe73d1909a2448a004a88362a1a532d0d4f7c3 (diff)
add basic nanovg bindings
Diffstat (limited to 'src')
-rw-r--r--src/image/image.c2
-rw-r--r--src/vector/CMakeLists.txt9
-rw-r--r--src/vector/vector.c83
-rw-r--r--src/vector/vector.h6
4 files changed, 99 insertions, 1 deletions
diff --git a/src/image/image.c b/src/image/image.c
index 64b7330..aeff333 100644
--- a/src/image/image.c
+++ b/src/image/image.c
@@ -2,7 +2,7 @@
#include <honeysuckle.h>
#include <cairo/cairo.h>
/* assimp provides its own stb_image implementation */
-#define STB_IMAGE_IMPLEMENTATION
+/*#define STB_IMAGE_IMPLEMENTATION*/
#include "stb_image.h"
#include "image.h"
diff --git a/src/vector/CMakeLists.txt b/src/vector/CMakeLists.txt
new file mode 100644
index 0000000..53032eb
--- /dev/null
+++ b/src/vector/CMakeLists.txt
@@ -0,0 +1,9 @@
+project(honey_engine)
+
+target_sources(honey PUBLIC
+ ${CMAKE_CURRENT_LIST_DIR}/vector.c
+)
+
+
+target_sources(test PUBLIC
+)
diff --git a/src/vector/vector.c b/src/vector/vector.c
new file mode 100644
index 0000000..230bfdd
--- /dev/null
+++ b/src/vector/vector.c
@@ -0,0 +1,83 @@
+#include <lua.h>
+#include <honeysuckle.h>
+#include "gl/glad/glad.h"
+#include <GLFW/glfw3.h>
+#define NANOVG_GL3_IMPLEMENTATION
+#include <nanovg.h>
+#include <nanovg_gl.h>
+#include "vector.h"
+
+
+static const char *nvg_ctx_tname = "nvg.Context";
+
+
+/* --===== contexts =====-- */
+
+int nvg_context(lua_State *L)
+{
+ struct NVGcontext **vg = lua_newuserdata(L, sizeof(struct NVGcontext *));
+ *vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
+ luaL_getmetatable(L, nvg_ctx_tname);
+ lua_setmetatable(L, -2);
+ return 1;
+}
+
+
+int nvg_delete(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgDeleteGL3(*vg);
+ return 0;
+}
+
+
+/* --===== frames =====-- */
+
+int nvg_begin_frame(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float width = luaL_checknumber(L, 2);
+ float height = luaL_checknumber(L, 3);
+ float pixelRatio = luaL_checknumber(L, 4);
+
+ nvgBeginFrame(*vg, width, height, pixelRatio);
+ return 0;
+}
+
+
+int nvg_cancel_frame(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgCancelFrame(*vg);
+ return 0;
+}
+
+
+int nvg_end_frame(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgEndFrame(*vg);
+ return 0;
+}
+
+
+
+/* --===== complete =====-- */
+
+void setup_nvg(lua_State *L, int honey_tbl)
+{
+ luaL_newmetatable(L, nvg_ctx_tname);
+ lua_pushcfunction(L, nvg_delete);
+ lua_setfield(L, -2, "__gc");
+ lua_pop(L, 1);
+
+ hs_create_table(L,
+ hs_str_cfunc("Context", nvg_context),
+
+ hs_str_cfunc("BeginFrame", nvg_begin_frame),
+ hs_str_cfunc("CancelFrame", nvg_cancel_frame),
+ hs_str_cfunc("EndFrame", nvg_end_frame),
+ );
+
+ lua_setfield(L, honey_tbl, "nvg");
+}
diff --git a/src/vector/vector.h b/src/vector/vector.h
new file mode 100644
index 0000000..1a08e8e
--- /dev/null
+++ b/src/vector/vector.h
@@ -0,0 +1,6 @@
+#ifndef HONEY_VECTOR_H
+#define HONEY_VECTOR_H
+
+void setup_nvg(lua_State *L, int honey_tbl);
+
+#endif