summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-05-20 20:51:05 -0500
committersanine-a <sanine.not@pm.me>2020-05-20 20:51:05 -0500
commit040ba6826237eb124aaa4576fc302e2e07dd40c5 (patch)
treec35f1c3c4a63f307ac8a0f6beac346e3d08b6b7d /include
parent447c3de585cca51013b17017d968e3aee53f5c87 (diff)
add honey_mesh and assorted related functions
Diffstat (limited to 'include')
-rw-r--r--include/common.h17
-rw-r--r--include/honey.h17
-rw-r--r--include/mesh.h59
-rw-r--r--include/shader.h2
4 files changed, 94 insertions, 1 deletions
diff --git a/include/common.h b/include/common.h
new file mode 100644
index 0000000..8c1f976
--- /dev/null
+++ b/include/common.h
@@ -0,0 +1,17 @@
+#ifndef HONEY_COMMON_H
+#define HONEY_COMMON_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "glad.h"
+#include <GLFW/glfw3.h>
+
+#include <cglm/cglm.h>
+#include <cglm/call.h>
+
+#include "stb_image.h"
+
+#endif
diff --git a/include/honey.h b/include/honey.h
new file mode 100644
index 0000000..251881e
--- /dev/null
+++ b/include/honey.h
@@ -0,0 +1,17 @@
+#ifndef HONEY_ENGINE_H
+#define HONEY_ENGINE_H
+
+#include "common.h"
+#include "mesh.h"
+#include "shader.h"
+
+typedef GLFWwindow* honey_window;
+
+honey_window honey_setup(int screen_width, int screen_height, char* window_title);
+
+#define honey_set_resize_callback glfwSetFramebufferSizeCallback
+#define honey_set_mouse_move_callback glfwSetCursorPosCallback
+
+#define honey_quit glfwTerminate
+
+#endif
diff --git a/include/mesh.h b/include/mesh.h
new file mode 100644
index 0000000..2040f44
--- /dev/null
+++ b/include/mesh.h
@@ -0,0 +1,59 @@
+/** @brief Defines the honey_mesh struct and related basic mesh functions. */
+
+#ifndef HONEY_MESH_H
+#define HONEY_MESH_H
+
+#include "common.h"
+#include "shader.h"
+
+enum honey_mesh_result {
+ MESH_OK,
+ MEMORY_ERROR,
+ BAD_VERTEX_DATA,
+ BAD_INDEX_DATA,
+ N_MESH_RESULTS };
+
+typedef struct {
+ float* vertices;
+ unsigned int n_vertices;
+ unsigned int* indices;
+ unsigned int n_indices;
+ unsigned int vertex_array, vertex_buffer, element_buffer;
+} honey_mesh;
+
+/** @brief Create a new mesh from vertex and index arrays.
+ *
+ * Note that this function creates copies of the vertex and index arrays,
+ * so you can deallocate those immediately.
+ *
+ * @param[out] mesh Pointer to the destination honey_mesh struct
+ * @param[in] vertices Array of floats representing the vertices
+ * @param[in] n_attributes The number of attributes per vertex
+ * @param[in] attribute_sizes An array containing for each attribute how many floats it contains
+ * @param[in] n_vertices The number of vertices (NOT the number of floats in the vertex array)
+ * @param[in] indices Array of vertex indices
+ * @param[in] n_indices The number of elements in the index array
+ */
+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);
+
+/** @brief Draw a mesh on screen.
+ *
+ * @param[in] mesh The mesh to draw
+ * @param[in] shader The shader to use when drawing the mesh
+ */
+void honey_mesh_draw(honey_mesh mesh,
+ honey_shader shader);
+
+/** @brief Delete a mesh.
+ *
+ * @param[in] mesh The mesh to delete
+ */
+void honey_mesh_delete(honey_mesh mesh);
+
+#endif
diff --git a/include/shader.h b/include/shader.h
index d43015d..bfdb090 100644
--- a/include/shader.h
+++ b/include/shader.h
@@ -6,7 +6,7 @@
#ifndef HONEY_SHADER_H
#define HONEY_SHADER_H
-#include <cglm/cglm.h>
+#include "common.h"
enum honey_shader_result {
SHADER_OK,