summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-31 14:01:55 -0500
committersanine-a <sanine.not@pm.me>2020-10-31 14:01:55 -0500
commit50d8b05f588d019a8a5ae1a76d22677b10553167 (patch)
tree6130b4c9367a663f64a9debba47625439e5fb997
parenta9f0521984f43f3048d3e0fec15082916e7f8331 (diff)
add basic texture bindings
-rw-r--r--src/honey.c3
-rw-r--r--src/texture/texture.c55
-rw-r--r--src/texture/texture.h9
-rw-r--r--src/window/window.c3
4 files changed, 66 insertions, 4 deletions
diff --git a/src/honey.c b/src/honey.c
index c63ab2f..1328a5f 100644
--- a/src/honey.c
+++ b/src/honey.c
@@ -82,6 +82,9 @@ bool honey_setup(lua_State** L)
honey_setup_primitives(*L);
lua_setfield(*L, -2, "primitives");
+ honey_setup_texture(*L);
+ lua_setfield(*L, -2, "texture");
+
lua_pushcfunction(*L, honey_exit);
lua_setfield(*L, -2, "exit");
diff --git a/src/texture/texture.c b/src/texture/texture.c
index 591ee11..1bb798a 100644
--- a/src/texture/texture.c
+++ b/src/texture/texture.c
@@ -1,6 +1,59 @@
#include "texture.h"
-enum honey_texture_result honey_texture_new(honey_texture* texture,
+static int honey_lua_texture_new(lua_State* L)
+{
+ honey_texture* texture = lua_newuserdata(L, sizeof(honey_texture));
+ return 1;
+}
+
+static int honey_lua_texture_load(lua_State* L)
+{
+ honey_texture* texture;
+ char* texture_path;
+ bool use_alpha;
+ honey_lua_parse_arguments(L, 3,
+ HONEY_USERDATA, &texture,
+ HONEY_STRING, &texture_path,
+ HONEY_BOOLEAN, &use_alpha);
+ enum honey_texture_result result = honey_texture_load(texture, texture_path, use_alpha);
+ if (result != TEXTURE_OK) {
+ char* error;
+ honey_format_string(&error,
+ "failed to load '%s'",
+ texture_path);
+ lua_pushstring(L, error);
+ free(error);
+ lua_error(L);
+ }
+
+ return 0;
+}
+
+static int honey_lua_texture_use(lua_State* L)
+{
+ honey_texture* texture;
+ int texture_unit;
+ honey_lua_parse_arguments(L, 2,
+ HONEY_USERDATA, &texture,
+ HONEY_INTEGER, &texture_unit);
+ honey_texture_use(*texture, texture_unit);
+ return 0;
+}
+
+void honey_setup_texture(lua_State* L)
+{
+ honey_lua_element texture_elements[] = {
+ { "new", HONEY_FUNCTION, { .function = honey_lua_texture_new } },
+ { "load", HONEY_FUNCTION, { .function = honey_lua_texture_load } },
+ { "use", HONEY_FUNCTION, { .function = honey_lua_texture_use } },
+ };
+
+ honey_lua_create_table(L, texture_elements, 3);
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+enum honey_texture_result honey_texture_load(honey_texture* texture,
char* texture_path,
bool alpha_channel) {
unsigned int texture_id;
diff --git a/src/texture/texture.h b/src/texture/texture.h
index 037d3d0..c9d1104 100644
--- a/src/texture/texture.h
+++ b/src/texture/texture.h
@@ -20,6 +20,9 @@ typedef struct {
int channels;
} honey_texture;
+/** @brief Place the honey.texture bindings as a table on the stack. */
+void honey_setup_texture(lua_State* L);
+
/** @brief Load a texture from disk.
*
* @param[out] texture Pointer to the destination texture
@@ -28,9 +31,9 @@ typedef struct {
*
* @return Success or failure type
*/
-enum honey_texture_result honey_texture_new(honey_texture* texture,
- char* texture_path,
- bool alpha_channel);
+enum honey_texture_result honey_texture_load(honey_texture* texture,
+ char* texture_path,
+ bool alpha_channel);
/** @brief Load a texture into a texture unit.
*
diff --git a/src/window/window.c b/src/window/window.c
index 263bd45..37053a4 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -94,6 +94,9 @@ bool honey_setup_window(lua_State* L)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ // Enable depth testing
+ glEnable(GL_DEPTH_TEST);
+
glfwSetWindowSizeCallback(info->window, honey_glfw_window_resize_callback);
glfwSetWindowFocusCallback(info->window, honey_glfw_window_focus_callback);