diff options
author | sanine-a <sanine.not@pm.me> | 2020-10-31 22:43:41 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-10-31 22:43:41 -0500 |
commit | 42d42c9ba3b741d167eaa2196c686962559686f1 (patch) | |
tree | 46f9d9c51d1d4fe1ccbacf1d1f73c066e93dfc32 /src/honey.c | |
parent | ad75604ec79d70d328595f114e65bac80db9999f (diff) |
add basic framebuffer operations
Diffstat (limited to 'src/honey.c')
-rw-r--r-- | src/honey.c | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/honey.c b/src/honey.c index 1328a5f..ce1a38c 100644 --- a/src/honey.c +++ b/src/honey.c @@ -54,6 +54,48 @@ bool honey_parse_options(honey_options* options, int argc, char** argv) } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +static int honey_lua_clear_color(lua_State* L) +{ + float* color_array; + bool color, depth, stencil; + honey_lua_parse_arguments(L, 4, + HONEY_USERDATA, &color_array, + HONEY_BOOLEAN, &color, + HONEY_BOOLEAN, &depth, + HONEY_BOOLEAN, &stencil); + float r = color_array[0]; + float g = color_array[1]; + float b = color_array[2]; + float a = color_array[3]; + + int clear_flags = 0; + if (color) + clear_flags = clear_flags | GL_COLOR_BUFFER_BIT; + if (depth) + clear_flags = clear_flags | GL_DEPTH_BUFFER_BIT; + if (stencil) + clear_flags = clear_flags | GL_STENCIL_BUFFER_BIT; + + glClearColor(r, g, b, a); + glClear(clear_flags); + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_lua_enable_depth_test(lua_State* L) +{ + bool enable; + honey_lua_parse_arguments(L, 1, HONEY_BOOLEAN, &enable); + if (enable) + glEnable(GL_DEPTH_TEST); + else + glDisable(GL_DEPTH_TEST); + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ bool honey_setup(lua_State** L) { @@ -88,6 +130,15 @@ bool honey_setup(lua_State** L) lua_pushcfunction(*L, honey_exit); lua_setfield(*L, -2, "exit"); + lua_pushcfunction(*L, honey_set_framebuffer); + lua_setfield(*L, -2, "set_framebuffer"); + + lua_pushcfunction(*L, honey_lua_clear_color); + lua_setfield(*L, -2, "clear_color"); + + lua_pushcfunction(*L, honey_lua_enable_depth_test); + lua_setfield(*L, -2, "enable_depth_test"); + lua_setglobal(*L, "honey"); return true; @@ -145,8 +196,6 @@ bool honey_run(lua_State* L, honey_options opts) { if (drawTime > 0.016) { drawTime -= 0.016; - glClearColor(0,0,0,1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (draw_callback != LUA_NOREF) { lua_rawgeti(L, LUA_REGISTRYINDEX, draw_callback); @@ -185,3 +234,13 @@ int honey_get_callback(lua_State* L, char* callback) return ref; } + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int honey_set_framebuffer(lua_State* L) +{ + int framebuffer; + honey_lua_parse_arguments(L, 1, HONEY_INTEGER, &framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + return 0; +} |