From 7afef0a9307aa4733a4862d8a140cc95886fdd8f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 5 Sep 2026 13:26:30 -0400 Subject: [PATCH] Can load the backpack model and if you hit R it will be made of glass. --- 24-cubemaps/config.json | 18 +++++++++++------- 24-cubemaps/src/components.hpp | 3 ++- 24-cubemaps/src/main.cpp | 4 ++++ 24-cubemaps/src/scene.cpp | 14 ++++++++------ 24-cubemaps/src/scene.hpp | 3 +++ 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/24-cubemaps/config.json b/24-cubemaps/config.json index 8c7d025..548f055 100644 --- a/24-cubemaps/config.json +++ b/24-cubemaps/config.json @@ -1,6 +1,10 @@ { "scene": { "shader": { + "vertex_path": "shaders/21-framebuffers.vert.glsl", + "frag_path": "shaders/21-framebuffers.frag.glsl" + }, + "reflect_shader": { "vertex_path": "shaders/24-vert.glsl", "frag_path": "shaders/24-frag.glsl" }, @@ -50,18 +54,18 @@ "window": { "directory": "assets", "model_path": "window.glb" + }, + "backpack": { + "directory": "assets/backpack", + "model_path": "backpack.obj" } }, "things": [ - {"model": "marble_cube", "position": [1.5, 0.0, -1.0], + {"model": "backpack", "position": [1.5, 0.0, -1.0], "rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]}, - "scale": 2.0, - "material": "default"}, - {"model": "window", "position": [1.5, 0.25, 0.0], - "rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]}, "scale": 1.0, - "material": "shiny"}, - {"model": "window", "position": [1.75, 0.25, 0.25], + "material": "default"}, + {"model": "marble_cube", "position": [1.5, 0.25, 0.0], "rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]}, "scale": 1.0, "material": "shiny"} diff --git a/24-cubemaps/src/components.hpp b/24-cubemaps/src/components.hpp index 8753f4c..61ba43b 100644 --- a/24-cubemaps/src/components.hpp +++ b/24-cubemaps/src/components.hpp @@ -102,6 +102,7 @@ namespace components { struct Scene { components::Shader shader; + components::Shader reflect_shader; components::Shader screen_shader; components::Shader skybox_shader; std::vector skybox_faces; @@ -112,5 +113,5 @@ namespace components { Lighting light; }; - ENROLL_COMPONENT(Scene, shader, screen_shader, skybox_shader, skybox_faces, materials, models, things, camera, light); + ENROLL_COMPONENT(Scene, shader, reflect_shader, screen_shader, skybox_shader, skybox_faces, materials, models, things, camera, light); } diff --git a/24-cubemaps/src/main.cpp b/24-cubemaps/src/main.cpp index 069b5fc..be6805c 100644 --- a/24-cubemaps/src/main.cpp +++ b/24-cubemaps/src/main.cpp @@ -70,6 +70,10 @@ void process_input(GLFWwindow *window, Scene& scene) { scene.camera.right(); } + if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { + scene.reflect_on = !scene.reflect_on; + } + if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { components::Rotation rotation{90.0f, {1.0f, 0.0f, 0.0f}}; scene.spawn("grass", scene.camera.position, rotation); diff --git a/24-cubemaps/src/scene.cpp b/24-cubemaps/src/scene.cpp index 6d8bc9a..369fbbe 100644 --- a/24-cubemaps/src/scene.cpp +++ b/24-cubemaps/src/scene.cpp @@ -31,12 +31,14 @@ void Scene::draw_thing(Shader& with_shader, Thing& thing) with_shader.setMat4("model", model); - thing.model.draw(with_shader, false); + // !reflect_on turns it on? yeah weird + thing.model.draw(with_shader, !reflect_on); } void Scene::render(GLFWwindow* window) { glm::mat4 view = camera.look_at(); glm::mat4 projection = glm::mat4(1.0f); + auto& with_shader = reflect_on ? reflect_shader : shader; // fov, aspect, near plane, far plane projection = glm::perspective(glm::radians(camera.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); @@ -44,13 +46,13 @@ void Scene::render(GLFWwindow* window) { framebuffer.begin(); // render the scene - shader.use(); - shader.setMat4("view", view); - shader.setMat4("projection", projection); - shader.setVec3("cameraPos", camera.position); + with_shader.use(); + with_shader.setMat4("view", view); + with_shader.setMat4("projection", projection); + with_shader.setVec3("cameraPos", camera.position); for(auto& thing : things) { - draw_thing(shader, thing); + draw_thing(with_shader, thing); } render_skybox(projection); diff --git a/24-cubemaps/src/scene.hpp b/24-cubemaps/src/scene.hpp index 152bf95..ffc3ac2 100644 --- a/24-cubemaps/src/scene.hpp +++ b/24-cubemaps/src/scene.hpp @@ -27,6 +27,7 @@ struct Thing { struct Scene { Shader shader; + Shader reflect_shader; Shader skybox_shader; std::vector skybox_faces; Screen screen; @@ -42,9 +43,11 @@ struct Scene { unsigned int skyboxVAO = 0; unsigned int skyboxVBO = 0; unsigned int skybox_texture_id = 0; + bool reflect_on = false; Scene(components::Scene& config): shader{config.shader.vertex_path, config.shader.frag_path}, + reflect_shader{config.reflect_shader.vertex_path, config.reflect_shader.frag_path}, skybox_shader{config.skybox_shader.vertex_path, config.skybox_shader.frag_path}, skybox_faces{config.skybox_faces}, screen{.shader={config.screen_shader.vertex_path, config.screen_shader.frag_path}},