From 03c8f7702917d7cfcae6cd92014c6ba6d169d747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Tue, 30 Dec 2025 12:01:31 +0100 Subject: [PATCH] feat: add imgui library & primitive shapes --- .gitmodules | 3 ++ lib/imgui | 1 + res/render/primitives/cube.frag | 31 +++++++++++++++++ res/render/primitives/cube.hpp | 60 +++++++++++++++++++++++++++++++++ res/render/primitives/cube.vert | 22 ++++++++++++ 5 files changed, 117 insertions(+) create mode 160000 lib/imgui create mode 100644 res/render/primitives/cube.frag create mode 100644 res/render/primitives/cube.hpp create mode 100644 res/render/primitives/cube.vert diff --git a/.gitmodules b/.gitmodules index 08861f5..bbd6522 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "lib/glad"] path = lib/glad url = https://github.com/DawidLokiec/glad.git +[submodule "lib/imgui"] + path = lib/imgui + url = https://github.com/ocornut/imgui.git diff --git a/lib/imgui b/lib/imgui new file mode 160000 index 0000000..922a11f --- /dev/null +++ b/lib/imgui @@ -0,0 +1 @@ +Subproject commit 922a11f0847fe1a7907345c31a22e0e77a43829c diff --git a/res/render/primitives/cube.frag b/res/render/primitives/cube.frag new file mode 100644 index 0000000..6f670ec --- /dev/null +++ b/res/render/primitives/cube.frag @@ -0,0 +1,31 @@ +#version 330 core +out vec4 FragColor; + +struct Material +{ + sampler2D diffuse; + vec3 specular; + float shininess; +}; +struct Light +{ + vec3 position; + + vec3 ambient; + vec3 diffuse; + vec3 specular; +}; + +in vec3 FragPos; +in vec3 Normal; +in vec2 TexCoords; + +uniform vec3 viewPos; +uniform Material material; +uniform Light light; + +void main() +{ + vec4 texColor = texture(material.diffuse , TexCoords); + FragColor = texColor; +} \ No newline at end of file diff --git a/res/render/primitives/cube.hpp b/res/render/primitives/cube.hpp new file mode 100644 index 0000000..716fc46 --- /dev/null +++ b/res/render/primitives/cube.hpp @@ -0,0 +1,60 @@ +#include "GLFW/glfw3.h" + + // Positions // Normales // texture coordinate +constexpr GLfloat VERTICE[] = { + // front side + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, + + // back side + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, + + // left side + -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, + -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, + -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, + + // right side + 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, + + // bottom side + -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, + + // up side + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, +}; + +constexpr unsigned int INDICE[] = { + 0, 1, 2, // 1 + 2, 3, 0, // 2 + + 4, 5, 6, // 3 + 6, 7, 4, // 4 + + 8, 9, 10, // 5 + 10, 11, 8, // 6 + + 12, 13, 14, // 7 + 14, 15, 12, // 8 + + 16, 17, 18, // 9 + 18, 19, 16, // 10 + + 20, 21, 22, // 11 + 22, 23, 20 // 12 +}; \ No newline at end of file diff --git a/res/render/primitives/cube.vert b/res/render/primitives/cube.vert new file mode 100644 index 0000000..407a580 --- /dev/null +++ b/res/render/primitives/cube.vert @@ -0,0 +1,22 @@ +#version 330 core + +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +uniform mat4 projection; +uniform mat4 model; +uniform mat4 view; + +out vec3 Normal; +out vec3 FragPos; +out vec2 TexCoords; + +void main() +{ + FragPos = vec3(model*vec4(aPos , 1.0)); + gl_Position = projection*view*vec4(FragPos , 1.0); + + Normal = mat3(transpose(inverse(model)))*aNormal; + TexCoords = aTexCoords; +} \ No newline at end of file