1 Commits

Author SHA1 Message Date
Jasper
7679555059 [ADD] added the menu buttons with correct textures to the scene 2021-06-01 15:10:23 +02:00
18 changed files with 108 additions and 103 deletions

2
.gitignore vendored
View File

@@ -428,6 +428,4 @@ FodyWeavers.xsd
**/docs/*
**/doc/*
**/pose_iter_160000.caffemodel
# End of https://www.toptal.com/developers/gitignore/api/c++,visualstudio,visualstudiocode,opencv

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
res/menu_item_quit1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
res/menu_item_start.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
res/menu_item_start1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -5,6 +5,11 @@
namespace gui
{
//Represents the type of the entitie
enum class GuiType{
LABEL, BUTTON
};
/*
* Structure for representing a gui item to display on the screen
*
@@ -12,12 +17,17 @@ namespace gui
* position = The center position of the gui
* scale = The size (scale) of the gui
*/
struct GuiTexture
{
int texture;
glm::vec2 position;
glm::vec2 scale;
virtual GuiType GetType() {
return GuiType::LABEL;
}
GuiTexture(int texture, glm::vec2 position, glm::vec2 scale): texture(texture), position(position), scale(scale)
{
scale.x /= (WINDOW_WIDTH / WINDOW_HEIGT);

View File

@@ -104,6 +104,10 @@ namespace gui
*/
void SetOnExitAction(void (*fun)()) { on_exit_action = fun; }
GuiType GetType() override {
return GuiType::BUTTON;
}
protected:
void OnClick() override { if (on_click_action != nullptr) on_click_action(); }
void OnEnter() override { if (on_enter_action != nullptr) on_enter_action(); }

View File

@@ -10,80 +10,46 @@
#include "../renderEngine/renderer.h"
#include "../shaders/entity_shader.h"
#include "../toolbox/toolbox.h"
#include <deque>
#define MAX_MODEL_DEQUE_SIZE 6 // max amount of models to load at the same time
#define UPCOMING_MODEL_AMOUNT 4 // how much models should be loaded in front of us
namespace scene
{
std::deque<entities::Entity> house_models;
std::deque<entities::Light> lights;
std::deque<entities::Entity> trees;
std::vector<entities::Entity> entities;
std::vector<entities::Light> lights;
models::RawModel raw_model;
models::ModelTexture texture;
shaders::EntityShader* shader;
shaders::GuiShader* gui_shader;
shaders::EntityShader *shader;
shaders::GuiShader *gui_shader;
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
std::vector<gui::GuiTexture*> guis;
models::TexturedModel model;
models::TexturedModel tree;
In_Game_Scene::In_Game_Scene()
{
shader = new shaders::EntityShader;
shader->Init();
shader->Init();
render_engine::renderer::Init(*shader);
gui_shader = new shaders::GuiShader();
gui_shader->Init();
}
/**
* @brief loads a new chunk in front of the camera, and deletes the chunk behind the camera.
*
* @param model_pos the amount of models the camera has passed already. This is the rounded result of (z position of camera) / (size of model)
*
*/
void load_chunk(int model_pos)
{
std::cout << "loading model chunk" << std::endl;
if (house_models.size() >= MAX_MODEL_DEQUE_SIZE)
{
house_models.pop_back();
trees.pop_back();
}
int z_offset = model_pos * (model.raw_model.model_size.x * 20); // how much "in the distance" we should load the model
house_models.push_front(entities::Entity(model, glm::vec3(0, -50, -50 - z_offset), glm::vec3(0, 90, 0), 20));
trees.push_front(entities::Entity(tree, glm::vec3(0, 0, -50 - z_offset), glm::vec3(0, 90, 0), 3));
}
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") };
texture.shine_damper = 10;
texture.reflectivity = 0;
model = { raw_model, texture };
models::RawModel raw_tree_model = render_engine::LoadObjModel("res/Tree.obj");
models::ModelTexture tree_texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
tree = { raw_tree_model, tree_texture };
models::TexturedModel model = { raw_model, texture };
// load the first few house models
for (int i = 0; i <= UPCOMING_MODEL_AMOUNT; i++)
int z = 0;
for (int i = 0; i < 5; ++i)
{
load_chunk(i);
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
z += (raw_model.model_size.x * 20);
}
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5))); // sun
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)));
@@ -92,11 +58,11 @@ namespace scene
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;
});
{
std::cout << "I got clicked on!" << std::endl;
});
guis.push_back(&button);
while (return_value == scene::Scenes::INGAME)
{
@@ -120,17 +86,13 @@ namespace scene
shader->Start();
shader->LoadSkyColor(render_engine::renderer::SKY_COLOR);
shader->LoadLightsDeque(lights);
shader->LoadLights(lights);
shader->LoadViewMatrix(camera);
for (entities::Entity& model_entity : house_models)
// Renders each entity in the entities list
for (entities::Entity& entity : entities)
{
render_engine::renderer::Render(model_entity, *shader);
}
for (entities::Entity& tree_entity : trees)
{
render_engine::renderer::Render(tree_entity, *shader);
render_engine::renderer::Render(entity, *shader);
}
// Render GUI items
@@ -143,18 +105,6 @@ namespace scene
void scene::In_Game_Scene::update(GLFWwindow* window)
{
camera.Move(window);
// calculate where the next house model should be loaded
static int last_model_pos = 0;
int model_pos = -round(camera.GetPosition().z / (model.raw_model.model_size.x * 20)); // how much models we have passed, minus because we are moving in the negative z axis
// if we have passed a model, load a new one and delete the one behind us
if (last_model_pos != model_pos)
{
load_chunk(model_pos + UPCOMING_MODEL_AMOUNT);
}
// remember the position at which the new model was added
last_model_pos = model_pos;
}
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)

View File

@@ -2,27 +2,96 @@
#include <GLFW/glfw3.h>
#include <map>
#include "startup_Scene.h"
#include <iostream>
#include "../models/model.h"
#include "../renderEngine/loader.h"
#include "../renderEngine/obj_loader.h"
#include "../renderEngine/renderer.h"
#include "../shaders/entity_shader.h"
#include "../toolbox/toolbox.h"
namespace scene
{
shaders::GuiShader* gui_shader1;
std::vector<gui::GuiTexture*> guis1;
Startup_Scene::Startup_Scene() {
shaders::EntityShader shader;
shader.Init();
render_engine::renderer::Init(shader);
shader.CleanUp();
gui_shader1 = new shaders::GuiShader();
gui_shader1->Init();
}
gui::Button* ConvertGuiTextureToButton(gui::GuiTexture* texture) {
if (texture->GetType() == gui::GuiType::BUTTON) {
return (gui::Button*)texture;
}
else {
return NULL;
}
}
scene::Scenes scene::Startup_Scene::start(GLFWwindow *window)
{
// GUI stuff
gui::Button button_start(render_engine::loader::LoadTexture("res/menu_item_start1.png"), glm::vec2(0.0f, 0.6f), glm::vec2(0.25f, 0.25f));
button_start.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_start1_hover.png"));
button_start.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_start1_click.png"));
button_start.SetOnClickAction([]()
{
std::cout << "Clicked on button: Start!" << std::endl;
});
guis1.push_back(&button_start);
gui::Button button_calibrate(render_engine::loader::LoadTexture("res/menu_item_calibrate1.png"), glm::vec2(0.0f, 0.0f), glm::vec2(0.25f, 0.25f));
button_calibrate.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_calibrate1_hover.png"));
button_calibrate.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_calibrate1_click.png"));
button_calibrate.SetOnClickAction([]()
{
std::cout << "Clicked on button: Calibrate!" << std::endl;
});
guis1.push_back(&button_calibrate);
gui::Button button_quit(render_engine::loader::LoadTexture("res/menu_item_quit1.png"), glm::vec2(0.0f, -0.6f), glm::vec2(0.25f, 0.25f));
button_quit.SetHoverTexture(render_engine::loader::LoadTexture("res/menu_item_quit1_hover.png"));
button_quit.SetClickedTexture(render_engine::loader::LoadTexture("res/menu_item_quit1_click.png"));
button_quit.SetOnClickAction([]()
{
std::cout << "Clicked on button: Quit!" << std::endl;
});
guis1.push_back(&button_quit);
while (return_value == scene::Scenes::STARTUP)
{
render();
update(window);
for (gui::GuiTexture* button : guis1) {
gui::Button* new_button = ConvertGuiTextureToButton(button);
if(new_button != NULL)
new_button->Update(window);
}
glfwSwapBuffers(window);
glfwPollEvents();
}
gui_shader1->CleanUp();
render_engine::loader::CleanUp();
return return_value;
}
void scene::Startup_Scene::render()
{
render_engine::renderer::Prepare();
// Render GUI items
render_engine::renderer::Render(guis1, *gui_shader1);
}
void scene::Startup_Scene::update(GLFWwindow* window)

View File

@@ -1,6 +1,6 @@
#pragma once
#include "scene.h"
#include <map>
#include "../gui/gui_interactable.h"
namespace scene
{
@@ -12,6 +12,8 @@ namespace scene
scene::Scenes return_value = scene::Scenes::STARTUP;
public:
Startup_Scene();
gui::Button* ConvertGuiTextureToButton(gui::GuiTexture* texture);
Scenes start(GLFWwindow* window) override;
void render() override;
void update(GLFWwindow* window) override;

View File

@@ -1,6 +1,5 @@
#include "entity_shader.h"
#include "../toolbox/toolbox.h"
#include <deque>
namespace shaders
{
@@ -161,25 +160,6 @@ namespace shaders
}
}
void EntityShader::LoadLightsDeque(std::deque<entities::Light>& lights) const
{
for (int i = 0; i < MAX_LIGHTS; ++i)
{
if (i < lights.size())
{
LoadVector(location_light_position[i], lights[i].GetPosition());
LoadVector(location_light_color[i], lights[i].GetColor());
LoadVector(location_light_attenuation[i], lights[i].GetAttenuation());
}
else
{
LoadVector(location_light_position[i], glm::vec3(0, 0, 0));
LoadVector(location_light_color[i], glm::vec3(0, 0, 0));
LoadVector(location_light_attenuation[i], glm::vec3(1, 0, 0));
}
}
}
void EntityShader::LoadShineVariables(float shine_damper, float reflectivity) const
{
LoadFloat(location_shine_damper, shine_damper);

View File

@@ -2,7 +2,6 @@
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
#include <deque>
#include "shader_program.h"
#include "../entities/camera.h"
#include "../entities/light.h"
@@ -59,13 +58,6 @@ namespace shaders
*/
void LoadLights(std::vector<entities::Light>& lights) const;
/**
* @brief loads some lights contained in a deque.
*
* @param lights the deque containing the lights to load
*/
void LoadLightsDeque(std::deque<entities::Light>& lights) const;
/*
* @brief: A method to load the the shine variables from a model into the shader
*