Merge remote-tracking branch 'origin/feature/adding_scenes' into feature/collision
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "gui_interactable.h"
|
||||
|
||||
|
||||
118
src/main.cpp
118
src/main.cpp
@@ -3,6 +3,7 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "stb_image.h"
|
||||
#include <ostream>
|
||||
@@ -16,9 +17,9 @@
|
||||
#include "renderEngine/renderer.h"
|
||||
#include "shaders/entity_shader.h"
|
||||
#include "toolbox/toolbox.h"
|
||||
#include "entities/collision_entity.h"
|
||||
#include "entities/player.h"
|
||||
#include "collision/collision_handler.h"
|
||||
#include "scenes/scene.h"
|
||||
#include "scenes/in_Game_Scene.h"
|
||||
#include "scenes/startup_Scene.h"
|
||||
|
||||
#pragma comment(lib, "glfw3.lib")
|
||||
#pragma comment(lib, "glew32s.lib")
|
||||
@@ -27,7 +28,7 @@
|
||||
static double UpdateDelta();
|
||||
|
||||
static GLFWwindow* window;
|
||||
|
||||
scene::Scene* current_scene;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -45,96 +46,51 @@ int main(void)
|
||||
glGetError();
|
||||
#pragma endregion
|
||||
|
||||
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
});
|
||||
|
||||
|
||||
models::RawModel raw_model = render_engine::LoadObjModel("res/House.obj");
|
||||
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/Texture.png") };
|
||||
texture.shine_damper = 10;
|
||||
texture.reflectivity = 0;
|
||||
models::TexturedModel model = { raw_model, texture };
|
||||
|
||||
|
||||
// load and add some models (in this case some level sections) to the entities list.
|
||||
std::vector<entities::Entity*> entities;
|
||||
std::vector<entities::CollisionEntity*> collision_entities;
|
||||
|
||||
// int z = 0;
|
||||
// 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));
|
||||
// z += (raw_model.model_size.x * 20);
|
||||
// }
|
||||
|
||||
std::vector<entities::Light> lights;
|
||||
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)));
|
||||
|
||||
|
||||
// Collision testing
|
||||
entities::Player player(model, glm::vec3(0, 0, 0), glm::vec3(0, 0, 0), 1, { {0, 0, 0}, raw_model.model_size });
|
||||
entities.push_back(&player);
|
||||
collision_entities.push_back(&player);
|
||||
|
||||
entities::Player2 player2(model, glm::vec3(50, 0, 0), glm::vec3(0, 0, 0), 1, { {50, 0, 0}, raw_model.model_size });
|
||||
entities.push_back(&player2);
|
||||
collision_entities.push_back(&player2);
|
||||
|
||||
|
||||
shaders::EntityShader shader;
|
||||
shader.Init();
|
||||
render_engine::renderer::Init(shader);
|
||||
|
||||
entities::Camera camera(glm::vec3(40, 10, 80), glm::vec3(0, 0, 0));
|
||||
current_scene = new scene::Startup_Scene();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
current_scene->onKey(window, key, scancode, action, mods);
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
});
|
||||
|
||||
bool window_open = true;
|
||||
// Main game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
while (!glfwWindowShouldClose(window) && window_open)
|
||||
{
|
||||
// Update
|
||||
//Update
|
||||
const double delta = UpdateDelta();
|
||||
camera.Move(window);
|
||||
|
||||
scene::Scenes return_value = current_scene->start(window);
|
||||
delete current_scene;
|
||||
|
||||
player.Update();
|
||||
player2.Update();
|
||||
switch (return_value) {
|
||||
case scene::Scenes::STOP:
|
||||
window_open = false;
|
||||
break;
|
||||
|
||||
collision::CheckCollisions(collision_entities);
|
||||
|
||||
case scene::Scenes::STARTUP:
|
||||
current_scene = new scene::Startup_Scene();
|
||||
break;
|
||||
|
||||
// Render
|
||||
render_engine::renderer::Prepare();
|
||||
|
||||
// Start rendering the entities
|
||||
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);
|
||||
}
|
||||
case scene::Scenes::INGAME:
|
||||
current_scene = new scene::In_Game_Scene();
|
||||
break;
|
||||
|
||||
// Stop rendering the entities
|
||||
shader.Stop();
|
||||
|
||||
// Finish up
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
default:
|
||||
std::cout << "Wrong return value!!! ->" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
shader.CleanUp();
|
||||
render_engine::loader::CleanUp();
|
||||
// Clean up -> preventing memory leaks!!!
|
||||
std::cout << "ending..." << std::endl;
|
||||
delete current_scene;
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
@@ -146,4 +102,4 @@ static double UpdateDelta()
|
||||
double delt_time = current_time - last_frame_time;
|
||||
last_frame_time = current_time;
|
||||
return delt_time;
|
||||
}
|
||||
}
|
||||
|
||||
118
src/scenes/in_Game_Scene.cpp
Normal file
118
src/scenes/in_Game_Scene.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "in_Game_Scene.h"
|
||||
#include "startup_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
|
||||
{
|
||||
std::vector<entities::Entity> entities;
|
||||
std::vector<entities::Light> lights;
|
||||
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()
|
||||
{
|
||||
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") };
|
||||
texture.shine_damper = 10;
|
||||
texture.reflectivity = 0;
|
||||
models::TexturedModel model = { raw_model, texture };
|
||||
|
||||
int z = 0;
|
||||
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));
|
||||
z += (raw_model.model_size.x * 20);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
// Render
|
||||
render_engine::renderer::Prepare();
|
||||
|
||||
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 GUI items
|
||||
render_engine::renderer::Render(guis, *gui_shader);
|
||||
|
||||
// Stop rendering the entities
|
||||
shader->Stop();
|
||||
}
|
||||
|
||||
void scene::In_Game_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
camera.Move(window);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
src/scenes/in_Game_Scene.h
Normal file
22
src/scenes/in_Game_Scene.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
|
||||
class In_Game_Scene : public scene::Scene
|
||||
{
|
||||
private:
|
||||
scene::Scenes return_value = scene::Scenes::INGAME;
|
||||
|
||||
public:
|
||||
In_Game_Scene();
|
||||
|
||||
Scenes start(GLFWwindow* window) override;
|
||||
void render() override;
|
||||
void update(GLFWwindow* window) 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 "scene.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
31
src/scenes/scene.h
Normal file
31
src/scenes/scene.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace scene {
|
||||
|
||||
enum class Scenes
|
||||
{
|
||||
STARTUP,
|
||||
INGAME,
|
||||
GAMEOVER,
|
||||
CALIBRATION,
|
||||
STOP
|
||||
};
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
virtual Scenes start(GLFWwindow* window) = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void update(GLFWwindow* window) = 0;
|
||||
virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {};
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
40
src/scenes/startup_Scene.cpp
Normal file
40
src/scenes/startup_Scene.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <map>
|
||||
#include "startup_Scene.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
|
||||
scene::Scenes scene::Startup_Scene::start(GLFWwindow *window)
|
||||
{
|
||||
while (return_value == scene::Scenes::STARTUP)
|
||||
{
|
||||
render();
|
||||
update(window);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
void scene::Startup_Scene::render()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void scene::Startup_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
{
|
||||
return_value = scene::Scenes::INGAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/scenes/startup_Scene.h
Normal file
22
src/scenes/startup_Scene.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
#include <map>
|
||||
|
||||
namespace scene
|
||||
{
|
||||
extern GLFWwindow* window;
|
||||
|
||||
class Startup_Scene : public scene::Scene
|
||||
{
|
||||
private:
|
||||
scene::Scenes return_value = scene::Scenes::STARTUP;
|
||||
|
||||
public:
|
||||
Scenes start(GLFWwindow* window) override;
|
||||
void render() override;
|
||||
void update(GLFWwindow* window) override;
|
||||
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\collision\collision_handler.cpp" />
|
||||
<ClCompile Include="src\scenes\in_Game_Scene.cpp" />
|
||||
<ClCompile Include="src\scenes\scene.cpp" />
|
||||
<ClCompile Include="src\entities\camera.cpp" />
|
||||
<ClCompile Include="src\entities\collision_entity.cpp" />
|
||||
<ClCompile Include="src\entities\entity.cpp" />
|
||||
@@ -32,10 +34,13 @@
|
||||
<ClCompile Include="src\shaders\shader_program.cpp" />
|
||||
<ClCompile Include="src\shaders\entity_shader.cpp" />
|
||||
<ClCompile Include="src\toolbox\toolbox.cpp" />
|
||||
<ClCompile Include="src\scenes\startup_Scene.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\collision\collision.h" />
|
||||
<ClInclude Include="src\collision\collision_handler.h" />
|
||||
<ClInclude Include="src\scenes\in_Game_Scene.h" />
|
||||
<ClInclude Include="src\scenes\scene.h" />
|
||||
<ClInclude Include="src\entities\camera.h" />
|
||||
<ClInclude Include="src\entities\collision_entity.h" />
|
||||
<ClInclude Include="src\entities\entity.h" />
|
||||
@@ -52,6 +57,7 @@
|
||||
<ClInclude Include="src\shaders\entity_shader.h" />
|
||||
<ClInclude Include="src\stb_image.h" />
|
||||
<ClInclude Include="src\toolbox\toolbox.h" />
|
||||
<ClInclude Include="src\scenes\startup_Scene.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
||||
@@ -48,6 +48,15 @@
|
||||
<ClCompile Include="src\gui\gui_interactable.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\scenes\scene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\scenes\in_Game_Scene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\scenes\startup_Scene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\entities\collision_entity.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -98,6 +107,15 @@
|
||||
<ClInclude Include="src\gui\gui_interactable.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\scenes\scene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\scenes\in_Game_Scene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\scenes\startup_Scene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\entities\collision_entity.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||
Reference in New Issue
Block a user