summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-03-10 02:33:42 -0600
committersanine <sanine.not@pm.me>2023-03-10 02:33:42 -0600
commitc2329b4c8258baa9429c77566c9def97d00e96d7 (patch)
tree029da1a4a2c5ac7bd7714ee70f195378f5c68c8e
parent51c7235d4e0a2df109dd5050328a0ad4a1878ae4 (diff)
demonstrate working glfw refactored bindings
-rw-r--r--demo/basic/main.lua13
-rw-r--r--src/glfw/setup.c11
-rw-r--r--src/glfw/setup.h1
-rw-r--r--src/glfw/window.c12
4 files changed, 29 insertions, 8 deletions
diff --git a/demo/basic/main.lua b/demo/basic/main.lua
index 0950690..b7899a6 100644
--- a/demo/basic/main.lua
+++ b/demo/basic/main.lua
@@ -1,18 +1,21 @@
local glfw = honey.glfw
+local gl = honey.gl
local err = glfw.Init()
-print(err, glfw.TRUE)
if err ~= glfw.TRUE then
local err, desc = glfw.GetError()
error("failed to initialize glfw: " .. tostring(err))
end
-local window = glfw.CreateWindow(640, 480, "Hello world c:", nil, nil)
+
+local window = glfw.CreateWindow(640, 480, "Hello world c:", glfw.monitor_NULL, glfw.window_NULL)
+glfw.SetJoystickCallback(function(jid, event) print(jid, event) end)
glfw.MakeContextCurrent(window)
-while (glfw.WindowShouldClose(window) ~= glfw.FALSE) do
- gl.Clear(gl.COLOR_BUFFER_BIT)
- glfw.SwapBUffers(window)
+gl.InitGlad()
+while (glfw.WindowShouldClose(window) == glfw.FALSE) do
+ honey.gl.Clear(honey.gl.COLOR_BUFFER_BIT)
+ glfw.SwapBuffers(window)
glfw.PollEvents()
end
diff --git a/src/glfw/setup.c b/src/glfw/setup.c
index 0abab35..4ba49a4 100644
--- a/src/glfw/setup.c
+++ b/src/glfw/setup.c
@@ -1,5 +1,6 @@
#include <lua.h>
#include <lauxlib.h>
+#include <GLFW/glfw3.h>
#include "util/util.h"
#include "setup.h"
@@ -29,5 +30,15 @@ void setup_glfw(lua_State *L, int honey_tbl)
};
create_table(L, tbl);
+ int t = lua_gettop(L);
+
+ GLFWwindow ** window_null = create_window(L);
+ *window_null = NULL;
+ lua_setfield(L, t, "window_NULL");
+
+ GLFWmonitor ** monitor_null = create_monitor(L);
+ *monitor_null = NULL;
+ lua_setfield(L, t, "monitor_NULL");
+
lua_setfield(L, honey_tbl, "glfw");
}
diff --git a/src/glfw/setup.h b/src/glfw/setup.h
index 1b30728..4226c3b 100644
--- a/src/glfw/setup.h
+++ b/src/glfw/setup.h
@@ -29,6 +29,7 @@ struct h_glfw_window_data_t {
};
+GLFWwindow ** create_window(lua_State *L);
GLFWmonitor ** create_monitor(lua_State *L);
diff --git a/src/glfw/window.c b/src/glfw/window.c
index 1aafeb4..0199fb0 100644
--- a/src/glfw/window.c
+++ b/src/glfw/window.c
@@ -19,11 +19,18 @@ GLFWwindow ** create_window(lua_State *L)
luaL_getmetatable(L, glfw_window_tname);
lua_setmetatable(L, -2);
- /* configure window data struct */
d->data.L = L;
lua_pushvalue(L, self);
d->data.self_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+ return window;
+}
+
+static void configure_window(GLFWwindow **window)
+{
+ struct window_data_t *d = (struct window_data_t *) window;
+
+ /* configure window data struct */
d->data.key_cb_ref = LUA_NOREF;
d->data.char_cb_ref = LUA_NOREF;
d->data.char_mods_cb_ref = LUA_NOREF;
@@ -43,8 +50,6 @@ GLFWwindow ** create_window(lua_State *L)
d->data.content_scale_cb_ref = LUA_NOREF;
glfwSetWindowUserPointer(*window, &(d->data));
-
- return window;
}
@@ -83,6 +88,7 @@ int glfwCreateWindow_bind(lua_State *L)
GLFWwindow ** window = create_window(L);
*window = glfwCreateWindow(width, height, title, *monitor, *share);
+ configure_window(window);
return 1;
}