diff options
author | sanine <sanine.not@pm.me> | 2022-08-23 13:38:27 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-23 13:38:27 -0500 |
commit | 3afbf2a13b2dada445fb667bf25600407fea480a (patch) | |
tree | 551329e6f74fc9f177616de0d6739e8b5331ae96 /src/gl/gl.c | |
parent | 261e3f991221fbad6bbf262f5e65b773e4b6c73e (diff) | |
parent | 25ed7eb9f84e9a822f698ad803901fbb2a5354cf (diff) |
:wMerge branch 'gl-window' into main
Diffstat (limited to 'src/gl/gl.c')
-rw-r--r-- | src/gl/gl.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/gl/gl.c b/src/gl/gl.c new file mode 100644 index 0000000..4639d48 --- /dev/null +++ b/src/gl/gl.c @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <stdbool.h> +#include "gl/glad/glad.h" +#include <GLFW/glfw3.h> +#include <lua.h> +#include <honeysuckle.h> +#include "gl.h" + +/* needs to be here because glad uses macros to define glBufferData */ +#ifdef HONEY_TEST_H +#undef glBufferData +#define glBufferData mock_glBufferData_ +#endif + + +int gl_init(lua_State *L); +int glad_init(lua_State *L); +int gl_terminate(lua_State *L); +int gl_get_error(lua_State *L); + +void setup_gl(lua_State *L, int honey_index) +{ + int gl_index = hs_create_table(L, + /* functions */ + hs_str_cfunc("Init", gl_init), + hs_str_cfunc("InitGlad", glad_init), + hs_str_cfunc("Terminate", gl_terminate), + hs_str_cfunc("GetError", gl_get_error), + + /******** enums ********/ + /* data types */ + hs_str_int("UNSIGNED_BYTE", GL_UNSIGNED_BYTE), + hs_str_int("UNSIGNED_INT", GL_UNSIGNED_INT), + hs_str_int("INT", GL_INT), + hs_str_int("FLOAT", GL_FLOAT), + + /* error types */ + hs_str_int("NO_ERROR", GL_NO_ERROR), + hs_str_int("INVALID_ENUM", GL_INVALID_ENUM), + hs_str_int("INVALID_VALUE", GL_INVALID_VALUE), + hs_str_int("INVALID_OPERATION", GL_INVALID_OPERATION), + hs_str_int("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION), + hs_str_int("OUT_OF_MEMORY", GL_OUT_OF_MEMORY), + ); + + setup_shader(L, gl_index); + setup_drawing(L, gl_index); + setup_data(L, gl_index); + setup_texture(L, gl_index); + + lua_setfield(L, honey_index, "gl"); +} + + +int gl_init(lua_State *L) +{ + if (!glfwInit()) { + hs_throw_error(L, "failed to initialize GLFW"); + } + return 0; +} + + +int glad_init(lua_State *L) +{ + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + hs_throw_error(L, "failed to initialize GLAD"); + } +} + + +int gl_terminate(lua_State *L) +{ + glfwTerminate(); + return 0; +} + + +int gl_get_error(lua_State *L) +{ + lua_pushinteger(L, glGetError()); + return 1; +} |