Develop into master #9
BIN
res/background_grey.png
Normal file
BIN
res/background_grey.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 294 KiB |
@@ -63,7 +63,7 @@ int main(void)
|
|||||||
|
|
||||||
current_scene->onKey(window, key, scancode, action, mods);
|
current_scene->onKey(window, key, scancode, action, mods);
|
||||||
});
|
});
|
||||||
|
|
||||||
bool window_open = true;
|
bool window_open = true;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,13 @@
|
|||||||
|
|
||||||
namespace scene
|
namespace scene
|
||||||
{
|
{
|
||||||
std::vector<entities::Entity> entities;
|
/**
|
||||||
std::vector<entities::Light> lights;
|
* sets up the first things when the objects has been made
|
||||||
models::RawModel raw_model;
|
*/
|
||||||
models::ModelTexture texture;
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
In_Game_Scene::In_Game_Scene()
|
In_Game_Scene::In_Game_Scene()
|
||||||
{
|
{
|
||||||
|
camera = new entities::Camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
shader = new shaders::EntityShader;
|
shader = new shaders::EntityShader;
|
||||||
shader->Init();
|
shader->Init();
|
||||||
render_engine::renderer::Init(*shader);
|
render_engine::renderer::Init(*shader);
|
||||||
@@ -33,7 +28,19 @@ namespace scene
|
|||||||
gui_shader = new shaders::GuiShader();
|
gui_shader = new shaders::GuiShader();
|
||||||
gui_shader->Init();
|
gui_shader->Init();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* deletes certain veriables when the object will be deleted, prevents memory leaks
|
||||||
|
*/
|
||||||
|
In_Game_Scene::~In_Game_Scene()
|
||||||
|
{
|
||||||
|
delete camera;
|
||||||
|
delete shader;
|
||||||
|
delete gui_shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the game scene, calls the render and update methods in a while loop
|
||||||
|
*/
|
||||||
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
|
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
raw_model = render_engine::LoadObjModel("res/House.obj");
|
raw_model = render_engine::LoadObjModel("res/House.obj");
|
||||||
@@ -45,7 +52,7 @@ namespace scene
|
|||||||
int z = 0;
|
int z = 0;
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
|
entities_to_render.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
|
||||||
z += (raw_model.model_size.x * 20);
|
z += (raw_model.model_size.x * 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +61,7 @@ namespace scene
|
|||||||
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), 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 stuff
|
||||||
gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(0.25f, 0.25f));
|
gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(1, 1));
|
||||||
button.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png"));
|
button.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png"));
|
||||||
button.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png"));
|
button.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png"));
|
||||||
button.SetOnClickAction([]()
|
button.SetOnClickAction([]()
|
||||||
@@ -64,11 +71,54 @@ namespace scene
|
|||||||
guis.push_back(&button);
|
guis.push_back(&button);
|
||||||
|
|
||||||
|
|
||||||
|
//guis for the pause menu
|
||||||
|
gui::GuiTexture background(render_engine::loader::LoadTexture("res/background_grey.png"), glm::vec2(0, 0), glm::vec2(1, 1));
|
||||||
|
pause_guis.push_back(&background);
|
||||||
|
|
||||||
|
gui::Button pause_button_resume(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0, 0), glm::vec2(0.25f, 0.25f));
|
||||||
|
pause_button_resume.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png"));
|
||||||
|
pause_button_resume.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png"));
|
||||||
|
pause_button_resume.SetOnClickAction([]()
|
||||||
|
{
|
||||||
|
std::cout << "I got clicked on the resume button!" << std::endl;
|
||||||
|
});
|
||||||
|
pause_guis.push_back(&pause_button_resume);
|
||||||
|
|
||||||
|
gui::Button pause_button_quit(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.3f, 0.0f), glm::vec2(0.25f, 0.25f));
|
||||||
|
pause_button_quit.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png"));
|
||||||
|
pause_button_quit.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png"));
|
||||||
|
pause_button_quit.SetOnClickAction([]()
|
||||||
|
{
|
||||||
|
std::cout << "I got clicked on the quit button!" << std::endl;
|
||||||
|
});
|
||||||
|
pause_guis.push_back(&pause_button_quit);
|
||||||
|
|
||||||
|
|
||||||
|
//the scene loop, this while loop represent the scene
|
||||||
while (return_value == scene::Scenes::INGAME)
|
while (return_value == scene::Scenes::INGAME)
|
||||||
{
|
{
|
||||||
update(window);
|
//checks the current game state, so it can render the correct models for each state
|
||||||
button.Update(window);
|
switch (game_state)
|
||||||
render();
|
{
|
||||||
|
/*case scene::Game_State::IDLE:
|
||||||
|
break;*/
|
||||||
|
|
||||||
|
case scene::Game_State::PAUSED:
|
||||||
|
render();
|
||||||
|
render_pause_menu();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case scene::Game_State::RUNNING:
|
||||||
|
update(window);
|
||||||
|
button.Update(window);
|
||||||
|
render();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cout << "Game state unknown" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
@@ -79,40 +129,58 @@ namespace scene
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renders the game models
|
||||||
|
*/
|
||||||
void scene::In_Game_Scene::render()
|
void scene::In_Game_Scene::render()
|
||||||
{
|
{
|
||||||
// Render
|
// Render
|
||||||
render_engine::renderer::Prepare();
|
render_engine::renderer::Prepare();
|
||||||
|
//starts the shader and begins to render
|
||||||
shader->Start();
|
shader->Start();
|
||||||
shader->LoadSkyColor(render_engine::renderer::SKY_COLOR);
|
shader->LoadSkyColor(render_engine::renderer::SKY_COLOR);
|
||||||
shader->LoadLights(lights);
|
shader->LoadLights(lights);
|
||||||
shader->LoadViewMatrix(camera);
|
shader->LoadViewMatrix(*camera);
|
||||||
|
|
||||||
// Renders each entity in the entities list
|
// Renders each entity in the entities list
|
||||||
for (entities::Entity& entity : entities)
|
for (entities::Entity& entity : entities_to_render)
|
||||||
{
|
{
|
||||||
render_engine::renderer::Render(entity, *shader);
|
render_engine::renderer::Render(entity, *shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render GUI items
|
// Render GUI items
|
||||||
render_engine::renderer::Render(guis, *gui_shader);
|
//render_engine::renderer::Render(guis, *gui_shader);
|
||||||
|
|
||||||
// Stop rendering the entities
|
// Stop rendering the entities
|
||||||
shader->Stop();
|
shader->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//updates certain variables
|
||||||
void scene::In_Game_Scene::update(GLFWwindow* window)
|
void scene::In_Game_Scene::update(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
camera.Move(window);
|
camera->Move(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//renders the models for the pause menu
|
||||||
|
void In_Game_Scene::render_pause_menu()
|
||||||
|
{
|
||||||
|
render_engine::renderer::Render(pause_guis, *gui_shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
//manages the key input in the game scene
|
||||||
void scene::In_Game_Scene::onKey(GLFWwindow* window, 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)
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
return_value = scene::Scenes::STOP;
|
return_value = scene::Scenes::STOP;
|
||||||
}
|
}
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
game_state = scene::Game_State::PAUSED;
|
||||||
|
}
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
game_state = scene::Game_State::RUNNING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,100 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <vector>
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
#include "../gui/gui_interactable.h"
|
||||||
|
#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
|
namespace scene
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* This enum is for managing the game scene state.
|
||||||
|
* for example: when pressed on a specific button, the game will be in a paused state and nothing about the player or the speed of the game will be updated
|
||||||
|
* and the pause screen will show up.
|
||||||
|
**/
|
||||||
|
enum class Game_State
|
||||||
|
{
|
||||||
|
//IDLE,
|
||||||
|
RUNNING,
|
||||||
|
PAUSED
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class In_Game_Scene : public scene::Scene
|
class In_Game_Scene : public scene::Scene
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
//return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene.
|
||||||
scene::Scenes return_value = scene::Scenes::INGAME;
|
scene::Scenes return_value = scene::Scenes::INGAME;
|
||||||
|
//game_state is an enum that keeps track of the current game state. For example: is the game running(thus the user is playing the game) of is the game paused.
|
||||||
|
scene::Game_State game_state = scene::Game_State::RUNNING;
|
||||||
|
|
||||||
|
//entities_to_render is a list of entities, those entities will be rendered in the 3D environment.
|
||||||
|
std::vector<entities::Entity> entities_to_render;
|
||||||
|
//lights is a lost of light points in the game, for example the sun or it can be used to attach light effects to lamps.
|
||||||
|
std::vector<entities::Light> lights;
|
||||||
|
|
||||||
|
models::RawModel raw_model;
|
||||||
|
models::ModelTexture texture;
|
||||||
|
//the shader that is used for rendering the models.
|
||||||
|
shaders::EntityShader* shader;
|
||||||
|
//the gui_shader is used of rendering the gui models (for example the pause buttons).
|
||||||
|
shaders::GuiShader* gui_shader;
|
||||||
|
//camera is the camera view of the game scene, this camera will be behind the main character.
|
||||||
|
entities::Camera *camera;
|
||||||
|
//guis is a list of all the gui components that needs to be load in the scene.
|
||||||
|
std::vector<gui::GuiTexture*> guis;
|
||||||
|
//pause_guis is a list of components that will be rendered when the game is paused.
|
||||||
|
std::vector<gui::GuiTexture*> pause_guis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief renders the objects/gui models
|
||||||
|
* @param
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void render_pause_menu();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
In_Game_Scene();
|
In_Game_Scene();
|
||||||
|
~In_Game_Scene();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the method start is the start of the scene where a while loop runs, this runs the scene.
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @return Scene value that indicates in which scene the application is
|
||||||
|
*/
|
||||||
Scenes start(GLFWwindow* window) override;
|
Scenes start(GLFWwindow* window) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method renders the models for the game scene
|
||||||
|
* @param
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method updates the models/variables for the game scene
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void update(GLFWwindow* window) override;
|
void update(GLFWwindow* window) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method updates the models/variables for the game scene
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @param key this is the keycode on which key has been pressed
|
||||||
|
* @param scancode -
|
||||||
|
* @param action-
|
||||||
|
* @param mods -
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
|
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/scenes/scene.cpp
Normal file
7
src/scenes/scene.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
scene::Scene::~Scene()
|
||||||
|
{
|
||||||
|
std::cout << "Main scene class gone!" << std::endl;
|
||||||
|
}
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
namespace scene {
|
namespace scene {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this enum represents the scenes in the game, those wil help to keep track in which scene the game is.
|
||||||
|
*/
|
||||||
enum class Scenes
|
enum class Scenes
|
||||||
{
|
{
|
||||||
STARTUP,
|
STARTUP,
|
||||||
@@ -18,14 +21,40 @@ namespace scene {
|
|||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~Scene() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the method start is the start of a scene where a while loop runs, this runs the scene.
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @return Scene value that indicates in which scene the application is
|
||||||
|
*/
|
||||||
virtual Scenes start(GLFWwindow* window) = 0;
|
virtual Scenes start(GLFWwindow* window) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method renders the models for a scene
|
||||||
|
* @param
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method updates the models/variables for a scene
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
virtual void update(GLFWwindow* window) = 0;
|
virtual void update(GLFWwindow* window) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief this method updates the models/variables for a scene
|
||||||
|
* @param window the main window of the application
|
||||||
|
* @param key this is the keycode on which key has been pressed
|
||||||
|
* @param scancode -
|
||||||
|
* @param action-
|
||||||
|
* @param mods -
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {};
|
virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -164,6 +165,9 @@ namespace scene
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renders the models in the start-up scene
|
||||||
|
*/
|
||||||
void scene::Startup_Scene::render()
|
void scene::Startup_Scene::render()
|
||||||
{
|
{
|
||||||
render_engine::renderer::Prepare();
|
render_engine::renderer::Prepare();
|
||||||
@@ -172,6 +176,9 @@ namespace scene
|
|||||||
render_engine::renderer::Render(guis1, *gui_shader1);
|
render_engine::renderer::Render(guis1, *gui_shader1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates the variables for the start-up scene
|
||||||
|
*/
|
||||||
void scene::Startup_Scene::update(GLFWwindow* window)
|
void scene::Startup_Scene::update(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
for (gui::GuiTexture* button : guis1) {
|
for (gui::GuiTexture* button : guis1) {
|
||||||
@@ -181,6 +188,9 @@ namespace scene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages the key input in the start-up scene
|
||||||
|
*/
|
||||||
void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace scene
|
|||||||
class Startup_Scene : public scene::Scene
|
class Startup_Scene : public scene::Scene
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
//return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene.
|
||||||
scene::Scenes return_value = scene::Scenes::STARTUP;
|
scene::Scenes return_value = scene::Scenes::STARTUP;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
<ClCompile Include="src\renderEngine\loader.cpp" />
|
<ClCompile Include="src\renderEngine\loader.cpp" />
|
||||||
<ClCompile Include="src\renderEngine\obj_loader.cpp" />
|
<ClCompile Include="src\renderEngine\obj_loader.cpp" />
|
||||||
<ClCompile Include="src\renderEngine\renderer.cpp" />
|
<ClCompile Include="src\renderEngine\renderer.cpp" />
|
||||||
|
<ClCompile Include="src\scenes\scene.cpp" />
|
||||||
<ClCompile Include="src\shaders\gui_shader.cpp" />
|
<ClCompile Include="src\shaders\gui_shader.cpp" />
|
||||||
<ClCompile Include="src\shaders\shader_program.cpp" />
|
<ClCompile Include="src\shaders\shader_program.cpp" />
|
||||||
<ClCompile Include="src\shaders\entity_shader.cpp" />
|
<ClCompile Include="src\shaders\entity_shader.cpp" />
|
||||||
|
|||||||
@@ -78,6 +78,9 @@
|
|||||||
<ClCompile Include="src\computervision\MenuTest.cpp">
|
<ClCompile Include="src\computervision\MenuTest.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\scenes\scene.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\entities\Camera.h">
|
<ClInclude Include="src\entities\Camera.h">
|
||||||
|
|||||||
Reference in New Issue
Block a user