Can load the backpack model and if you hit R it will be made of glass.

This commit is contained in:
Zed A. Shaw 2026-09-05 13:26:30 -04:00
parent 29f1606085
commit 7afef0a930
5 changed files with 28 additions and 14 deletions

View file

@ -1,6 +1,10 @@
{ {
"scene": { "scene": {
"shader": { "shader": {
"vertex_path": "shaders/21-framebuffers.vert.glsl",
"frag_path": "shaders/21-framebuffers.frag.glsl"
},
"reflect_shader": {
"vertex_path": "shaders/24-vert.glsl", "vertex_path": "shaders/24-vert.glsl",
"frag_path": "shaders/24-frag.glsl" "frag_path": "shaders/24-frag.glsl"
}, },
@ -50,18 +54,18 @@
"window": { "window": {
"directory": "assets", "directory": "assets",
"model_path": "window.glb" "model_path": "window.glb"
},
"backpack": {
"directory": "assets/backpack",
"model_path": "backpack.obj"
} }
}, },
"things": [ "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]}, "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, "scale": 1.0,
"material": "shiny"}, "material": "default"},
{"model": "window", "position": [1.75, 0.25, 0.25], {"model": "marble_cube", "position": [1.5, 0.25, 0.0],
"rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]}, "rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]},
"scale": 1.0, "scale": 1.0,
"material": "shiny"} "material": "shiny"}

View file

@ -102,6 +102,7 @@ namespace components {
struct Scene { struct Scene {
components::Shader shader; components::Shader shader;
components::Shader reflect_shader;
components::Shader screen_shader; components::Shader screen_shader;
components::Shader skybox_shader; components::Shader skybox_shader;
std::vector<std::string> skybox_faces; std::vector<std::string> skybox_faces;
@ -112,5 +113,5 @@ namespace components {
Lighting light; 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);
} }

View file

@ -70,6 +70,10 @@ void process_input(GLFWwindow *window, Scene& scene) {
scene.camera.right(); 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) { if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
components::Rotation rotation{90.0f, {1.0f, 0.0f, 0.0f}}; components::Rotation rotation{90.0f, {1.0f, 0.0f, 0.0f}};
scene.spawn("grass", scene.camera.position, rotation); scene.spawn("grass", scene.camera.position, rotation);

View file

@ -31,12 +31,14 @@ void Scene::draw_thing(Shader& with_shader, Thing& thing)
with_shader.setMat4("model", model); 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) { void Scene::render(GLFWwindow* window) {
glm::mat4 view = camera.look_at(); glm::mat4 view = camera.look_at();
glm::mat4 projection = glm::mat4(1.0f); glm::mat4 projection = glm::mat4(1.0f);
auto& with_shader = reflect_on ? reflect_shader : shader;
// fov, aspect, near plane, far plane // fov, aspect, near plane, far plane
projection = glm::perspective(glm::radians(camera.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); 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(); framebuffer.begin();
// render the scene // render the scene
shader.use(); with_shader.use();
shader.setMat4("view", view); with_shader.setMat4("view", view);
shader.setMat4("projection", projection); with_shader.setMat4("projection", projection);
shader.setVec3("cameraPos", camera.position); with_shader.setVec3("cameraPos", camera.position);
for(auto& thing : things) { for(auto& thing : things) {
draw_thing(shader, thing); draw_thing(with_shader, thing);
} }
render_skybox(projection); render_skybox(projection);

View file

@ -27,6 +27,7 @@ struct Thing {
struct Scene { struct Scene {
Shader shader; Shader shader;
Shader reflect_shader;
Shader skybox_shader; Shader skybox_shader;
std::vector<std::string> skybox_faces; std::vector<std::string> skybox_faces;
Screen screen; Screen screen;
@ -42,9 +43,11 @@ struct Scene {
unsigned int skyboxVAO = 0; unsigned int skyboxVAO = 0;
unsigned int skyboxVBO = 0; unsigned int skyboxVBO = 0;
unsigned int skybox_texture_id = 0; unsigned int skybox_texture_id = 0;
bool reflect_on = false;
Scene(components::Scene& config): Scene(components::Scene& config):
shader{config.shader.vertex_path, config.shader.frag_path}, 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_shader{config.skybox_shader.vertex_path, config.skybox_shader.frag_path},
skybox_faces{config.skybox_faces}, skybox_faces{config.skybox_faces},
screen{.shader={config.screen_shader.vertex_path, config.screen_shader.frag_path}}, screen{.shader={config.screen_shader.vertex_path, config.screen_shader.frag_path}},