diff options
author | 2025-02-07 11:27:18 -0500 | |
---|---|---|
committer | 2025-02-07 11:27:18 -0500 | |
commit | 4da7be39827ea5888ef9c97b1aadf61b0d76347c (patch) | |
tree | 15d0ff8f8bcb0e871efb1b2e65c2bc8d07b17565 /mons_3d/include |
initial commit (lol)
Diffstat (limited to 'mons_3d/include')
-rw-r--r-- | mons_3d/include/camera.h | 12 | ||||
-rw-r--r-- | mons_3d/include/color.h | 12 | ||||
-rw-r--r-- | mons_3d/include/light.h | 12 | ||||
-rw-r--r-- | mons_3d/include/mesh.h | 14 | ||||
-rw-r--r-- | mons_3d/include/model.h | 19 | ||||
-rw-r--r-- | mons_3d/include/projection.h | 13 | ||||
-rw-r--r-- | mons_3d/include/shader.h | 35 | ||||
-rw-r--r-- | mons_3d/include/texture.h | 19 | ||||
-rw-r--r-- | mons_3d/include/transform.h | 36 | ||||
-rw-r--r-- | mons_3d/include/vertex.h | 15 |
10 files changed, 187 insertions, 0 deletions
diff --git a/mons_3d/include/camera.h b/mons_3d/include/camera.h new file mode 100644 index 0000000..be795bb --- /dev/null +++ b/mons_3d/include/camera.h @@ -0,0 +1,12 @@ +#ifndef MONS_CAMERA_H +#define MONS_CAMERA_H + +#include "projection.h" +#include "transform.h" + +typedef struct mons_camera { + mons_transform transform; + mons_projection projection; +} mons_camera; + +#endif diff --git a/mons_3d/include/color.h b/mons_3d/include/color.h new file mode 100644 index 0000000..85b68c0 --- /dev/null +++ b/mons_3d/include/color.h @@ -0,0 +1,12 @@ +#ifndef MONS_COLOR_H +#define MONS_COLOR_H + +#include "mons_math/vec4.h" + +#define MONS_COLOR_BLACK (mons_vec4){0,0,0,1} +#define MONS_COLOR_WHITE MONS_VEC4_ONE +#define MONS_COLOR_RED (mons_vec4){1,0,0,1} +#define MONS_COLOR_GREEN (mons_vec4){0,1,0,1} +#define MONS_COLOR_BLUE (mons_vec4){0,0,1,1} + +#endif diff --git a/mons_3d/include/light.h b/mons_3d/include/light.h new file mode 100644 index 0000000..8f1aac2 --- /dev/null +++ b/mons_3d/include/light.h @@ -0,0 +1,12 @@ +#ifndef MONS_LIGHT_H +#define MONS_LIGHT_H + +#include "transform.h" +#include "mons_math/vec4.h" + +typedef struct mons_directional_light { + mons_transform transform; + mons_vec4 color; +} mons_directional_light; + +#endif diff --git a/mons_3d/include/mesh.h b/mons_3d/include/mesh.h new file mode 100644 index 0000000..3794697 --- /dev/null +++ b/mons_3d/include/mesh.h @@ -0,0 +1,14 @@ +#ifndef MONS_MESH_H +#define MONS_MESH_H + +struct mons_vertex; +typedef unsigned int mons_vao; + +typedef struct mons_mesh { + mons_vao vao; + unsigned int element_count; +} mons_mesh; + +mons_mesh mons_create_mesh(struct mons_vertex *vertex_array, int vertex_count, int *index_array, int index_count); + +#endif diff --git a/mons_3d/include/model.h b/mons_3d/include/model.h new file mode 100644 index 0000000..9059d64 --- /dev/null +++ b/mons_3d/include/model.h @@ -0,0 +1,19 @@ +#ifndef MONS_MODEL_H +#define MONS_MODEL_H + +#include "mesh.h" +#include "shader.h" +#include "transform.h" +#include "texture.h" + +typedef struct mons_model { + mons_mesh mesh; + mons_program shader; + mons_transform transform; + mons_texture *textures; + unsigned int textures_len; +} mons_model; + +void mons_model_draw(mons_model model); + +#endif diff --git a/mons_3d/include/projection.h b/mons_3d/include/projection.h new file mode 100644 index 0000000..df0f716 --- /dev/null +++ b/mons_3d/include/projection.h @@ -0,0 +1,13 @@ +#ifndef MONS_PROJECTION_H +#define MONS_PROJECTION_H + +typedef struct mons_projection { + float near; + float far; + float fov; + float aspect_ratio; +} mons_projection; + +struct mons_mat4 mons_projection_matrix(mons_projection projection); + +#endif diff --git a/mons_3d/include/shader.h b/mons_3d/include/shader.h new file mode 100644 index 0000000..553c6e4 --- /dev/null +++ b/mons_3d/include/shader.h @@ -0,0 +1,35 @@ +#ifndef MONS_SHADER_H +#define MONS_SHADER_H + +#include <glad/gl.h> +#include <stdbool.h> + +typedef unsigned int mons_shader; +typedef unsigned int mons_program; + +typedef enum mons_shader_type { + MONS_SHADER_TYPE_VERTEX = GL_VERTEX_SHADER, + MONS_SHADER_TYPE_FRAGMENT = GL_FRAGMENT_SHADER, +} mons_shader_type; + +struct mons_vec2; +struct mons_vec3; +struct mons_vec4; +struct mons_mat4; + +mons_shader mons_create_shader(mons_shader_type type, char *source, int len); +mons_program mons_create_program(mons_shader vertex_shader, mons_shader fragment_shader); +void mons_shader_set_float(mons_program shader, char *uniform_name, float value); +void mons_shader_set_vec2(mons_program shader, char *uniform_name, struct mons_vec2 value); +void mons_shader_set_vec3(mons_program shader, char *uniform_name, struct mons_vec3 value); +void mons_shader_set_vec4(mons_program shader, char *uniform_name, struct mons_vec4 value); +void mons_shader_set_mat4(mons_program shader, char *uniform_name, struct mons_mat4 value, bool transpose); + +void mons_shader_set_float_global(char *uniform_name, float value); +void mons_shader_set_vec2_global(char *uniform_name, struct mons_vec2 value); +void mons_shader_set_vec3_global(char *uniform_name, struct mons_vec3 value); +void mons_shader_set_vec4_global(char *uniform_name, struct mons_vec4 value); +void mons_shader_set_mat4_global(char *uniform_name, struct mons_mat4 value, bool transpose); +void mons_shader_apply_global_uniforms(mons_program shader); + +#endif diff --git a/mons_3d/include/texture.h b/mons_3d/include/texture.h new file mode 100644 index 0000000..4e3d2e4 --- /dev/null +++ b/mons_3d/include/texture.h @@ -0,0 +1,19 @@ +#ifndef MONS_TEXTURE_H +#define MONS_TEXTURE_H + +#include "image.h" +#include "shader.h" +#include <stdio.h> + +typedef struct mons_texture { + unsigned int id; + unsigned int width; + unsigned int height; +} mons_texture; + +mons_texture mons_texture_from_image(mons_image image); +mons_texture mons_texture_load(FILE *stream); + +void mons_texture_bind(mons_program shader, unsigned int unit, mons_texture texture); + +#endif diff --git a/mons_3d/include/transform.h b/mons_3d/include/transform.h new file mode 100644 index 0000000..840dfc2 --- /dev/null +++ b/mons_3d/include/transform.h @@ -0,0 +1,36 @@ +#ifndef MONS_TRANSFORM_H +#define MONS_TRANSFORM_H + +#include "mons_math/mat4.h" +#include "mons_math/vec3.h" +#include "mons_math/quat.h" + +typedef struct mons_transform { + mons_vec3 translation; + mons_vec3 scale; + mons_quat rotation; +} mons_transform; + +void mons_transform_translate(mons_transform *transform, struct mons_vec3 translation); +void mons_transform_rotate(mons_transform *transform, struct mons_quat rotation); +void mons_transform_scale(mons_transform *transform, struct mons_vec3 scale); + +mons_mat4 mons_transform_matrix(mons_transform transform); + +void mons_transform_set_translation(mons_transform *transform, struct mons_vec3 translation); +void mons_transform_set_rotation(mons_transform *transform, struct mons_quat rotation); +void mons_transform_set_scale(mons_transform *transform, struct mons_vec3 scale); + +struct mons_vec3 mons_transform_forward(mons_transform transform); +struct mons_vec3 mons_transform_up(mons_transform transform); +struct mons_vec3 mons_transform_right(mons_transform transform); + +void mons_transform_look_at(mons_transform *transform, mons_vec3 point, mons_vec3 up); + +#define MONS_TRANSFORM_IDENTITY (mons_transform) {\ + MONS_VEC3_ZERO,\ + MONS_VEC3_ONE,\ + MONS_QUAT_IDENTITY,\ +} + +#endif diff --git a/mons_3d/include/vertex.h b/mons_3d/include/vertex.h new file mode 100644 index 0000000..5e95579 --- /dev/null +++ b/mons_3d/include/vertex.h @@ -0,0 +1,15 @@ +#ifndef MONS_VERTEX_H +#define MONS_VERTEX_H + +#include "mons_math/vec4.h" +#include "mons_math/vec3.h" +#include "mons_math/vec2.h" + +typedef struct mons_vertex { + mons_vec3 position; + mons_vec3 normal; + mons_vec4 tangent; + mons_vec2 texture_coords; +} mons_vertex; + +#endif |