[ADD] The scene switching works now, the only thing to do is controling the scenes with the keys!

This commit is contained in:
Lars
2021-05-28 16:04:41 +02:00
parent 93b3223737
commit 5d31327a47
7 changed files with 133 additions and 139 deletions

View File

@@ -1,3 +1,4 @@
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "in_Game_Scene.h"
@@ -17,13 +18,23 @@ namespace scene
std::vector<entities::Light> lights;
models::RawModel raw_model;
models::ModelTexture texture;
shaders::EntityShader shader;
shaders::EntityShader *shader;
shaders::GuiShader *gui_shader;
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
extern GLFWwindow* window;
std::vector<gui::GuiTexture*> guis;
void scene::In_Game_Scene::start()
In_Game_Scene::In_Game_Scene()
{
shader = new shaders::EntityShader;
shader->Init();
render_engine::renderer::Init(*shader);
gui_shader = new shaders::GuiShader();
gui_shader->Init();
}
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
{
raw_model = render_engine::LoadObjModel("res/House.obj");
texture = { render_engine::loader::LoadTexture("res/Texture.png") };
@@ -38,13 +49,34 @@ namespace scene
z += (raw_model.model_size.x * 20);
}
shader.Init();
render_engine::renderer::Init(shader);
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5)));
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
// GUI stuff
gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(0.25f, 0.25f));
button.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png"));
button.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png"));
button.SetOnClickAction([]()
{
std::cout << "I got clicked on!" << std::endl;
});
guis.push_back(&button);
while (return_value == scene::Scenes::INGAME)
{
update(window);
button.Update(window);
render();
glfwSwapBuffers(window);
glfwPollEvents();
}
shader->CleanUp();
gui_shader->CleanUp();
render_engine::loader::CleanUp();
return return_value;
}
void scene::In_Game_Scene::render()
@@ -52,28 +84,35 @@ namespace scene
// Render
render_engine::renderer::Prepare();
shader.Start();
shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
shader.LoadLights(lights);
shader.LoadViewMatrix(camera);
shader->Start();
shader->LoadSkyColor(render_engine::renderer::SKY_COLOR);
shader->LoadLights(lights);
shader->LoadViewMatrix(camera);
// Renders each entity in the entities list
for (entities::Entity& entity : entities)
{
render_engine::renderer::Render(entity, shader);
render_engine::renderer::Render(entity, *shader);
}
// Render GUI items
render_engine::renderer::Render(guis, *gui_shader);
// Stop rendering the entities
shader.Stop();
shader->Stop();
}
void scene::In_Game_Scene::update()
void scene::In_Game_Scene::update(GLFWwindow* window)
{
camera.Move(window);
}
void scene::In_Game_Scene::onKey(int key, int scancode, int action, int mods)
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{
return_value = scene::Scenes::STOP;
}
}
}