summaryrefslogtreecommitdiff
path: root/src/gl/drawing.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-23 13:38:27 -0500
committersanine <sanine.not@pm.me>2022-08-23 13:38:27 -0500
commit3afbf2a13b2dada445fb667bf25600407fea480a (patch)
tree551329e6f74fc9f177616de0d6739e8b5331ae96 /src/gl/drawing.c
parent261e3f991221fbad6bbf262f5e65b773e4b6c73e (diff)
parent25ed7eb9f84e9a822f698ad803901fbb2a5354cf (diff)
:wMerge branch 'gl-window' into main
Diffstat (limited to 'src/gl/drawing.c')
-rw-r--r--src/gl/drawing.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/gl/drawing.c b/src/gl/drawing.c
new file mode 100644
index 0000000..e6b1e13
--- /dev/null
+++ b/src/gl/drawing.c
@@ -0,0 +1,81 @@
+#include "gl/glad/glad.h"
+#include <GLFW/glfw3.h>
+#include <lua.h>
+#include <honeysuckle.h>
+#include "util/util.h"
+
+int gl_set_viewport(lua_State *L);
+int gl_draw_arrays(lua_State *L);
+int gl_draw_elements(lua_State *L);
+int gl_set_clear_color(lua_State *L);
+int gl_clear(lua_State *L);
+
+void setup_drawing(lua_State *L, int gl_index)
+{
+ int tbl = hs_create_table(L,
+ /* functions */
+ hs_str_cfunc("DrawArrays", gl_draw_arrays),
+ hs_str_cfunc("DrawElements", gl_draw_elements),
+ hs_str_cfunc("ClearColor", gl_set_clear_color),
+ hs_str_cfunc("Clear", gl_clear),
+ hs_str_cfunc("Viewport", gl_set_viewport),
+
+ /******** enums ********/
+ /* rendering primitives */
+ hs_str_int("POINTS", GL_POINTS),
+ hs_str_int("LINES", GL_LINES),
+ hs_str_int("TRIANGLES", GL_TRIANGLES),
+
+ /* clear bitmasks */
+ hs_str_int("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT),
+ hs_str_int("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT),
+ hs_str_int("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT),
+ );
+
+ append_table(L, gl_index, tbl);
+ lua_pop(L, 1);
+}
+
+int gl_set_clear_color(lua_State *L)
+{
+ lua_Number r, g, b, a;
+ hs_parse_args(L, hs_num(r), hs_num(g), hs_num(b), hs_num(a));
+ glClearColor(r, g, b, a);
+ return 0;
+}
+
+
+int gl_clear(lua_State *L)
+{
+ lua_Integer mask;
+ hs_parse_args(L, hs_int(mask));
+ glClear(mask);
+ return 0;
+}
+
+
+int gl_draw_arrays(lua_State *L)
+{
+ lua_Integer mode, first, count;
+ hs_parse_args(L, hs_int(mode), hs_int(first), hs_int(count));
+ glDrawArrays(mode, first, count);
+ return 0;
+}
+
+
+int gl_draw_elements(lua_State *L)
+{
+ lua_Integer mode, count, type, offset;
+ hs_parse_args(L, hs_int(mode), hs_int(count), hs_int(type), hs_int(offset));
+ glDrawElements(mode, count, type, (const void*)offset);
+ return 0;
+}
+
+
+int gl_set_viewport(lua_State *L)
+{
+ lua_Integer x, y, w, h;
+ hs_parse_args(L, hs_int(x), hs_int(y), hs_int(w), hs_int(h));
+ glViewport(x, y, w, h);
+ return 0;
+}