summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-23 13:28:01 -0500
committersanine <sanine.not@pm.me>2022-08-23 13:28:01 -0500
commitae4e17fc743ca0344af818ab767db7311ea7829c (patch)
tree0dfad8ace50a0eaeb43f398a95f36dfd30822502 /src
parent711f530f7afe3358c674cf418ee067e7a4501699 (diff)
add basic transforms
Diffstat (limited to 'src')
-rw-r--r--src/gl/shader.c19
-rw-r--r--src/glm/CMakeLists.txt7
-rw-r--r--src/glm/glm.c13
-rw-r--r--src/glm/glm.h10
-rw-r--r--src/glm/mat4.c36
-rw-r--r--src/glm/transform.c31
-rw-r--r--src/main.c2
7 files changed, 117 insertions, 1 deletions
diff --git a/src/gl/shader.c b/src/gl/shader.c
index b4d03e6..3732aff 100644
--- a/src/gl/shader.c
+++ b/src/gl/shader.c
@@ -18,6 +18,8 @@ int gl_uniform_get_location(lua_State *L);
int gl_uniform_1i(lua_State *L);
int gl_uniform_4f(lua_State *L);
+int gl_uniform_matrix_4fv(lua_State *L);
+
void setup_shader(lua_State *L, int gl_index)
{
@@ -37,6 +39,8 @@ void setup_shader(lua_State *L, int gl_index)
hs_str_cfunc("Uniform1i", gl_uniform_1i),
hs_str_cfunc("Uniform4f", gl_uniform_4f),
+ hs_str_cfunc("UniformMatrix4fv", gl_uniform_matrix_4fv),
+
/******** enums ********/
/* shader types */
hs_str_int("VERTEX_SHADER", GL_VERTEX_SHADER),
@@ -63,7 +67,7 @@ int gl_shader_set_source(lua_State *L)
lua_Integer shader;
char *code;
hs_parse_args(L, hs_int(shader), hs_str(code));
- glShaderSource(shader, 1, &code, NULL);
+ glShaderSource(shader, 1, (const GLchar * const*)&code, NULL);
return 0;
}
@@ -161,3 +165,16 @@ int gl_uniform_4f(lua_State *L)
glUniform4f(location, v0, v1, v2, v3);
return 0;
}
+
+
+int gl_uniform_matrix_4fv(lua_State *L)
+{
+ lua_Integer location;
+ bool transpose;
+ void *ptr;
+ hs_parse_args(L, hs_int(location), hs_bool(transpose), hs_user(ptr));
+
+ float *value = ptr;
+ glUniformMatrix4fv(location, 1, transpose, value);
+ return 0;
+}
diff --git a/src/glm/CMakeLists.txt b/src/glm/CMakeLists.txt
new file mode 100644
index 0000000..962dbbd
--- /dev/null
+++ b/src/glm/CMakeLists.txt
@@ -0,0 +1,7 @@
+project(honey_engine)
+
+target_sources(honey PUBLIC
+ ${CMAKE_CURRENT_LIST_DIR}/glm.c
+ ${CMAKE_CURRENT_LIST_DIR}/mat4.c
+ ${CMAKE_CURRENT_LIST_DIR}/transform.c
+)
diff --git a/src/glm/glm.c b/src/glm/glm.c
new file mode 100644
index 0000000..786fcf0
--- /dev/null
+++ b/src/glm/glm.c
@@ -0,0 +1,13 @@
+#include <lua.h>
+#include <honeysuckle.h>
+
+
+void setup_glm(lua_State *L, int honey_index)
+{
+ lua_createtable(L, 0, 1);
+ int glm_index = lua_gettop(L);
+
+ setup_mat4(L, glm_index);
+ setup_transform(L, glm_index);
+ lua_setfield(L, honey_index, "glm");
+}
diff --git a/src/glm/glm.h b/src/glm/glm.h
new file mode 100644
index 0000000..2bf803b
--- /dev/null
+++ b/src/glm/glm.h
@@ -0,0 +1,10 @@
+#ifndef HONEY_GLM_H
+#define HONEY_GLM_H
+
+#include <lua.h>
+
+void setup_glm(lua_State *L, int honey_index);
+void setup_mat4(lua_State *L, int glm_index);
+void setup_transform(lua_State *L, int glm_index);
+
+#endif
diff --git a/src/glm/mat4.c b/src/glm/mat4.c
new file mode 100644
index 0000000..f98cdfb
--- /dev/null
+++ b/src/glm/mat4.c
@@ -0,0 +1,36 @@
+#include <lua.h>
+#include <honeysuckle.h>
+#include <cglm/cglm.h>
+#include "util/util.h"
+
+int mat4_create(lua_State *L);
+int mat4_identity(lua_State *L);
+
+void setup_mat4(lua_State *L, int glm_tbl)
+{
+ int tbl = hs_create_table(L,
+ hs_str_cfunc("mat4", mat4_create),
+ hs_str_cfunc("mat4_identity", mat4_identity),
+ );
+
+ append_table(L, glm_tbl, tbl);
+ lua_pop(L, 1);
+}
+
+
+int mat4_create(lua_State *L)
+{
+ lua_newuserdata(L, 16*sizeof(float));
+ return 1;
+}
+
+
+int mat4_identity(lua_State *L)
+{
+ void *ptr;
+ hs_parse_args(L, hs_user(ptr));
+ mat4 *m = ptr;
+
+ glm_mat4_identity(*m);
+ return 0;
+}
diff --git a/src/glm/transform.c b/src/glm/transform.c
new file mode 100644
index 0000000..4dce595
--- /dev/null
+++ b/src/glm/transform.c
@@ -0,0 +1,31 @@
+#include <lua.h>
+#include <honeysuckle.h>
+#include <cglm/cglm.h>
+#include "util/util.h"
+
+
+int rotate_z(lua_State *L);
+
+
+void setup_transform(lua_State *L, int glm_tbl)
+{
+ int tbl = hs_create_table(L,
+ hs_str_cfunc("rotate_z", rotate_z),
+ );
+
+ append_table(L, glm_tbl, tbl);
+ lua_pop(L, 1);
+}
+
+
+int rotate_z(lua_State *L)
+{
+ void *src_ptr, *dest_ptr;
+ lua_Number angle;
+ hs_parse_args(L, hs_user(src_ptr), hs_num(angle), hs_user(dest_ptr));
+ mat4 *source = src_ptr;
+ mat4 *dest = dest_ptr;
+
+ glm_rotate_z(*source, angle, *dest);
+ return 0;
+}
diff --git a/src/main.c b/src/main.c
index 66b1f11..5f5d399 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,7 @@
#include <honeysuckle.h>
#include "gl/gl.h"
#include "image/image.h"
+#include "glm/glm.h"
int main(int argc, char **argv)
@@ -16,6 +17,7 @@ int main(int argc, char **argv)
setup_gl(L, honey_index);
setup_window(L, honey_index);
setup_image(L, honey_index);
+ setup_glm(L, honey_index);
lua_setglobal(L, "honey");
int err = luaL_loadfile(L, "honey.lua");