From 040ba6826237eb124aaa4576fc302e2e07dd40c5 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Wed, 20 May 2020 20:51:05 -0500 Subject: add honey_mesh and assorted related functions --- src/honey_setup.c | 28 ++++++++++++++++++ src/mesh.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/primitives.c | 3 ++ src/shader.c | 2 -- 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/honey_setup.c create mode 100644 src/mesh.c create mode 100644 src/primitives.c (limited to 'src') diff --git a/src/honey_setup.c b/src/honey_setup.c new file mode 100644 index 0000000..247c325 --- /dev/null +++ b/src/honey_setup.c @@ -0,0 +1,28 @@ +#include "include/honey.h" + +honey_window honey_setup(int screen_width, int screen_height, char* window_title) { + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + honey_window window = glfwCreateWindow(screen_width, screen_height, window_title, NULL, NULL); + if (window == NULL) { + fprintf(stderr, "ERROR: failed to create window!\n"); + glfwTerminate(); + return NULL; + } + + glfwMakeContextCurrent(window); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + + if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) { + fprintf(stderr, "ERROR: failed to initialize GLAD!\n"); + glfwTerminate(); + return NULL; + } + + return window; +} + + diff --git a/src/mesh.c b/src/mesh.c new file mode 100644 index 0000000..1b0fb1a --- /dev/null +++ b/src/mesh.c @@ -0,0 +1,86 @@ +#include "include/mesh.h" + +enum honey_mesh_result honey_mesh_new(honey_mesh* mesh, + float* vertices, + unsigned int n_vertices, + unsigned int n_attributes, + unsigned int* attribute_sizes, + unsigned int* indices, + unsigned int n_indices) { + if (vertices == NULL || n_vertices == 0) { + return BAD_VERTEX_DATA; + } + if (indices == NULL || n_indices == 0) { + return BAD_INDEX_DATA; + } + + unsigned int vertex_size = 0; + for (int i=0; i -#include "include/glad.h" #include "include/shader.h" /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -- cgit v1.2.1