Can load the backpack model and if you hit R it will be made of glass.
This commit is contained in:
parent
29f1606085
commit
7afef0a930
5 changed files with 28 additions and 14 deletions
|
|
@ -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"}
|
||||
|
|
|
|||
|
|
@ -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<std::string> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ struct Thing {
|
|||
|
||||
struct Scene {
|
||||
Shader shader;
|
||||
Shader reflect_shader;
|
||||
Shader skybox_shader;
|
||||
std::vector<std::string> 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}},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue