diff --git a/Escape-the-Dawn.sln b/Escape-the-Dawn.sln index 213283c..a932c57 100644 --- a/Escape-the-Dawn.sln +++ b/Escape-the-Dawn.sln @@ -3,13 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Escape-the-Dawn", "Escape-the-Dawn\Escape-the-Dawn.vcxproj", "{FE405CFA-8FCE-4867-92CF-797E73B36482}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tests", "Tests\Tests.vcxproj", "{B9A8F4AA-BE85-45EA-84DD-652D13DD22BE}" - ProjectSection(ProjectDependencies) = postProject - {A9755CAA-62DC-442D-B82C-F548546CFD38} = {A9755CAA-62DC-442D-B82C-F548546CFD38} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Executable", "Executable\Executable.vcxproj", "{A9755CAA-62DC-442D-B82C-F548546CFD38}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -20,14 +13,6 @@ Global {FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.Build.0 = Debug|Win32 {FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.ActiveCfg = Release|Win32 {FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.Build.0 = Release|Win32 - {B9A8F4AA-BE85-45EA-84DD-652D13DD22BE}.Debug|Win32.ActiveCfg = Debug|Win32 - {B9A8F4AA-BE85-45EA-84DD-652D13DD22BE}.Debug|Win32.Build.0 = Debug|Win32 - {B9A8F4AA-BE85-45EA-84DD-652D13DD22BE}.Release|Win32.ActiveCfg = Release|Win32 - {B9A8F4AA-BE85-45EA-84DD-652D13DD22BE}.Release|Win32.Build.0 = Release|Win32 - {A9755CAA-62DC-442D-B82C-F548546CFD38}.Debug|Win32.ActiveCfg = Debug|Win32 - {A9755CAA-62DC-442D-B82C-F548546CFD38}.Debug|Win32.Build.0 = Debug|Win32 - {A9755CAA-62DC-442D-B82C-F548546CFD38}.Release|Win32.ActiveCfg = Release|Win32 - {A9755CAA-62DC-442D-B82C-F548546CFD38}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Escape-the-Dawn/Engine.h b/Escape-the-Dawn/Engine.h index 968dfed..283aa54 100644 --- a/Escape-the-Dawn/Engine.h +++ b/Escape-the-Dawn/Engine.h @@ -1,17 +1,12 @@ #include #include -#include -#define GLFW_INCLUDE_GLU -#include -#include +#include "Renderer.h" +#include "GameWorld.h" #include "logging.h" #include "glerror.h" -#include "Renderer.h" -#include "GameWorld.h" - class Engine { public: diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj b/Escape-the-Dawn/Escape-the-Dawn.vcxproj index dec759b..f34b012 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj @@ -16,13 +16,13 @@ - StaticLibrary + Application true MultiByte v110 - StaticLibrary + Application false true MultiByte @@ -40,7 +40,7 @@ - $(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Debug;$(SolutionDir)\Libraries\SOIL\lib\Debug;$(SolutionDir)\Libraries\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Debug;$(LibraryPath) + $(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Debug;$(SolutionDir)\Libraries\SOIL\lib\Debug;$(SolutionDir)\Libraries\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Debug;$(LibraryPath) $(SolutionDir)bin\ $(SolutionDir)obj\$(ProjectName)\ $(ProjectName)-$(Configuration) @@ -50,7 +50,7 @@ $(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) - $(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Release;$(SolutionDir)\Libraries\SOIL\lib\Release;$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath) + $(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Release;$(SolutionDir)\Libraries\SOIL\lib\Release;$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath) $(SolutionDir)bin\ $(SolutionDir)obj\$(ProjectName)\ $(ProjectName)-$(Configuration) @@ -65,7 +65,7 @@ true Console - opengl32.lib;glu32.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies) + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies) @@ -90,7 +90,7 @@ false true true - opengl32.lib;glu32.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies) + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies) OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib; @@ -101,7 +101,9 @@ + + @@ -147,6 +149,7 @@ + @@ -164,6 +167,8 @@ + + diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters index ef3542e..2ce6bb5 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters @@ -45,6 +45,8 @@ + + @@ -144,6 +146,7 @@ + @@ -152,6 +155,12 @@ Shaders + + Shaders + + + Shaders + Shaders diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig new file mode 100644 index 0000000..df95cf2 --- /dev/null +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig @@ -0,0 +1,186 @@ + + + + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + + + + GUI + + + + + GUI + + + GUI + + + GUI + + + GUI + + + + + + + + + + + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + + Components + + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + + + Components + + + Components + + + Components + + + Components + + + Util + + + Util + + + + + GUI + + + GUI + + + GUI + + + GUI + + + GUI + + + + + + + + + Shaders + + + Shaders + +<<<<<<< HEAD + +======= + + Shaders + + +>>>>>>> origin/master + Shaders + + + + + {657e11f4-52e7-4336-b77f-80f00b85c33f} + + + {59929465-a139-43b9-9c75-48121d156e78} + + + {54f1eb6f-dc00-4e97-a3ef-ac255d755e2e} + + + {d985d7a7-c041-46fe-ae03-aa40295a7aad} + + + {7bdb0f69-049e-4f16-b271-2495e02e4b28} + + + \ No newline at end of file diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp new file mode 100644 index 0000000..170772b --- /dev/null +++ b/Escape-the-Dawn/GameWorld.cpp @@ -0,0 +1,114 @@ +#include "GameWorld.h" + +void GameWorld::Initialize() +{ + World::Initialize(); + + //AddSystem("LevelGenerationSystem"); + AddSystem("InputSystem"); + //AddSystem("CollisionSystem"); + //AddSystem("ParticleSystem"); + AddSystem("PlayerSystem"); + AddSystem("SoundSystem"); + AddSystem("RenderSystem"); + + std::shared_ptr transform; + std::shared_ptr model; + std::shared_ptr pointLight; + std::shared_ptr camera; + EntityID ent; + + // Camera + ent = CreateEntity(); + SetProperty(ent, "Name", std::string("Camera")); + transform = AddComponent(ent, "Transform"); + AddComponent(ent, "Input"); + transform->Position = glm::vec3(0.f, 2.f, 10.f); + camera = AddComponent(ent, "Camera"); + camera->FOV = 45.f; + camera->FarClip = 1000.f; + camera->NearClip = 0.01f; + transform->Orientation = glm::angleAxis(glm::radians(25.0f),glm::vec3(1,0,0)); + + // Fucking lights + ent = CreateEntity(); + transform = AddComponent(ent, "Transform"); + transform->Position = glm::vec3(0.f, 4.f, 0.f); + pointLight = AddComponent(ent, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; + ent = CreateEntity(); + transform = AddComponent(ent, "Transform"); + transform->Position = glm::vec3(10.f, 4.f, 0.f); + pointLight = AddComponent(ent, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; + ent = CreateEntity(); + transform = AddComponent(ent, "Transform"); + transform->Position = glm::vec3(0.f, -4.f, 0.f); + pointLight = AddComponent(ent, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; + + // Player + ent = CreateEntity(); + transform = AddComponent(ent, "Transform"); + transform->Position = glm::vec3(10.f, 0.f, 0.f); + model = AddComponent(ent, "Model"); + model->ModelFile = "ship.obj"; + auto soundEmitter = AddComponent(ent, "SoundEmitter"); + soundEmitter->Gain = 0.1f; + soundEmitter->MaxDistance = FLT_MAX; + soundEmitter->ReferenceDistance = 10; + soundEmitter->Loop = true; + soundEmitter->Pitch = 0; + //GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); + +} + +void GameWorld::Update(double dt) +{ + World::Update(dt); +} + +void GameWorld::RegisterComponents() +{ + m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); }); + m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); }); + m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); }); + m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); }); + m_ComponentFactory.Register("Input", []() { return new Components::Input(); }); + m_ComponentFactory.Register("Model", []() { return new Components::Model(); }); + m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); }); + m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); }); + m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); }); + m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); }); + m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); }); + m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); }); + m_ComponentFactory.Register("Template", []() { return new Components::Template(); }); + m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); }); +} + +void GameWorld::RegisterSystems() +{ + //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); + m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); }); + //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); + //m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); + m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); + m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); + m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); }); +} + diff --git a/Escape-the-Dawn/GameWorld.h b/Escape-the-Dawn/GameWorld.h index d36b675..5a9e3bc 100644 --- a/Escape-the-Dawn/GameWorld.h +++ b/Escape-the-Dawn/GameWorld.h @@ -30,7 +30,8 @@ class GameWorld : public World { public: - GameWorld(std::shared_ptr renderer); + GameWorld(std::shared_ptr renderer) + : m_Renderer(renderer), World() { } void Initialize() override; void RegisterSystems() override; @@ -42,127 +43,4 @@ private: std::shared_ptr m_Renderer; }; -GameWorld::GameWorld(std::shared_ptr renderer) - : m_Renderer(renderer), World() -{ - -} - -void GameWorld::Initialize() -{ - World::Initialize(); - - //AddSystem("LevelGenerationSystem"); - AddSystem("InputSystem"); - //AddSystem("CollisionSystem"); - //AddSystem("ParticleSystem"); - AddSystem("PlayerSystem"); - AddSystem("SoundSystem"); - AddSystem("RenderSystem"); - - std::shared_ptr transform; - std::shared_ptr model; - std::shared_ptr pointLight; - std::shared_ptr camera; - EntityID ent; - - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, 0.f); - pointLight = AddComponent(ent, "PointLight"); - pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->constantAttenuation = 0.f; - pointLight->linearAttenuation = 1.f; - pointLight->quadraticAttenuation = 0.f; - pointLight->spotExponent = 0.0f; - - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(10.f, 4.f, 0.f); - pointLight = AddComponent(ent, "PointLight"); - pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->constantAttenuation = 0.f; - pointLight->linearAttenuation = 1.f; - pointLight->quadraticAttenuation = 0.f; - pointLight->spotExponent = 0.0f; - - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, -4.f, 0.f); - pointLight = AddComponent(ent, "PointLight"); - pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->constantAttenuation = 0.f; - pointLight->linearAttenuation = 1.f; - pointLight->quadraticAttenuation = 0.f; - pointLight->spotExponent = 0.0f; - - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(10.f, 0.f, 0.f); - model = AddComponent(ent, "Model"); - model->ModelFile = "ship.obj"; - - ent = CreateEntity(); - transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, 0.f, 0.f); - model = AddComponent(ent, "Model"); - model->ModelFile = "ship.obj"; -// auto soundEmitter = AddComponent(ent, "SoundEmitter"); -// soundEmitter->Gain = 1; -// soundEmitter->MaxDistance = FLT_MAX; -// soundEmitter->ReferenceDistance = 10; -// soundEmitter->Loop = true; -// soundEmitter->ReferenceDistance = 0.1; -// soundEmitter->Pitch = 1; -// GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); - - ent = CreateEntity(); - SetProperty(ent, "Name", std::string("Camera")); - transform = AddComponent(ent, "Transform"); - AddComponent(ent, "Input"); - transform->Position = glm::vec3(0.f, 2.f, 10.f); - camera = AddComponent(ent, "Camera"); - camera->FOV = 45.f; - camera->FarClip = 1000.f; - camera->NearClip = 0.01f; - transform->Orientation = glm::angleAxis(glm::radians(25.0f),glm::vec3(1,0,0)); -} - -void GameWorld::RegisterSystems() -{ - //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); - m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); }); - //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); - //m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); - m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); - m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); - m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); }); -} - -void GameWorld::RegisterComponents() -{ - m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); }); - m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); }); - m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); }); - m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); }); - m_ComponentFactory.Register("Input", []() { return new Components::Input(); }); - m_ComponentFactory.Register("Model", []() { return new Components::Model(); }); - m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); }); - m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); }); - m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); }); - m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); }); - m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); }); - m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); }); - m_ComponentFactory.Register("Template", []() { return new Components::Template(); }); - m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); }); -} - -void GameWorld::Update(double dt) -{ - World::Update(dt); -} - #endif // GameWorld_h__ diff --git a/Escape-the-Dawn/GameWorld.h.orig b/Escape-the-Dawn/GameWorld.h.orig index 2a5ebb8..aa409e9 100644 --- a/Escape-the-Dawn/GameWorld.h.orig +++ b/Escape-the-Dawn/GameWorld.h.orig @@ -42,6 +42,7 @@ private: std::shared_ptr m_Renderer; }; +<<<<<<< HEAD GameWorld::GameWorld(std::shared_ptr renderer) : m_Renderer(renderer), World() { @@ -88,6 +89,17 @@ void GameWorld::Initialize() pointLight->quadraticAttenuation = 0.f; pointLight->spotExponent = 0.0f; + ent = CreateEntity(); + transform = AddComponent(ent, "Transform"); + transform->Position = glm::vec3(0.f, -4.f, 0.f); + pointLight = AddComponent(ent, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; + ent = CreateEntity(); transform = AddComponent(ent, "Transform"); transform->Position = glm::vec3(10.f, 0.f, 0.f); @@ -99,24 +111,14 @@ void GameWorld::Initialize() transform->Position = glm::vec3(0.f, 0.f, 0.f); model = AddComponent(ent, "Model"); model->ModelFile = "ship.obj"; -<<<<<<< HEAD // auto soundEmitter = AddComponent(ent, "SoundEmitter"); // soundEmitter->Gain = 1; -// soundEmitter->MaxDistance = 10; +// soundEmitter->MaxDistance = FLT_MAX; +// soundEmitter->ReferenceDistance = 10; // soundEmitter->Loop = true; // soundEmitter->ReferenceDistance = 0.1; // soundEmitter->Pitch = 1; // GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); -======= - auto soundEmitter = AddComponent(ent, "SoundEmitter"); - soundEmitter->Gain = 1; - soundEmitter->MaxDistance = FLT_MAX; - soundEmitter->ReferenceDistance = 10; - soundEmitter->Loop = true; - - soundEmitter->Pitch = 1; - GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); ->>>>>>> 2c4d8fde9951da98e1e8527bba48ce3cd16d309c ent = CreateEntity(); SetProperty(ent, "Name", std::string("Camera")); @@ -164,4 +166,6 @@ void GameWorld::Update(double dt) World::Update(dt); } +======= +>>>>>>> origin/master #endif // GameWorld_h__ diff --git a/Escape-the-Dawn/Model.cpp b/Escape-the-Dawn/Model.cpp index 56b5db8..4ae2126 100644 --- a/Escape-the-Dawn/Model.cpp +++ b/Escape-the-Dawn/Model.cpp @@ -3,12 +3,55 @@ Model::Model(const char* path) { - - Loadobj(path, Vertices, Normals, TextureCoords); CreateBuffers(Vertices, Normals, TextureCoords); } +Model::Model(OBJ &obj) +{ + OBJ::MaterialInfo* currentMaterial = nullptr; + TextureGroup* currentTexGroup = nullptr; + int index = 0; + for (auto face : obj.Faces) { + // New material + if (face.Material != currentMaterial) { + currentMaterial = face.Material; + // Load texture + std::shared_ptr texture = std::make_shared(currentMaterial->TextureFile); + // TODO: Load material parameters + // Create new texture group (start index of new group is upcoming index) + TextureGroup texGroup = { texture, index, index }; + TextureGroups.push_back(texGroup); + currentTexGroup = &TextureGroups.back(); + } + + // Face definitions + for (auto faceDef : face.Definitions) { + glm::vec3 vertex; + std::tie(vertex.x, vertex.y, vertex.z) = obj.Vertices.at(faceDef.VertexIndex - 1); + Vertices.push_back(vertex); + + if (faceDef.NormalIndex != 0) { + glm::vec3 normal; + std::tie(normal.x, normal.y, normal.z) = obj.Normals.at(faceDef.NormalIndex - 1); + Normals.push_back(normal); + } + + if (faceDef.TextureCoordIndex != 0) { + glm::vec2 texCoord; + // TODO: W-coord? + std::tie(texCoord.x, texCoord.y, std::ignore) = obj.TextureCoords.at(faceDef.TextureCoordIndex - 1); + TextureCoords.push_back(texCoord); + } + + currentTexGroup->EndIndex = index; + index++; + } + } + + CreateBuffers(Vertices, Normals, TextureCoords); +} + bool Model::Loadobj(const char* path, std::vector & out_vertices, std::vector &out_normals, std::vector & out_TextureCoords) { std::vector< unsigned int > vertexIndices, TextureCoordIndices, normalIndices; diff --git a/Escape-the-Dawn/Model.h b/Escape-the-Dawn/Model.h index 5ce4c11..716d1c2 100644 --- a/Escape-the-Dawn/Model.h +++ b/Escape-the-Dawn/Model.h @@ -8,37 +8,48 @@ #include #include -#define _CRT_SECURE_NO_WARNINGS -#include -#define GLFW_INCLUDE_GLU -#include -#include -#define GLM_FORCE_RADIANS +#include "OpenGL.h" #include #include #include #include -#include "glerror.h" #include +#include + +#include "glerror.h" #include "Texture.h" +#include "OBJ.h" class Model { public: + Model(OBJ &obj); + Model(const char* path); + + struct TextureGroup + { + std::shared_ptr Texture; + unsigned int StartIndex; + unsigned int EndIndex; + }; + + GLuint VAO; + std::vector TextureGroups; + + std::vector> texture; + glm::mat4 GetMatrix(); std::vector Vertices; + +private: + std::vector Normals; std::vector TextureCoords; GLuint VertexBuffer; GLuint NormalBuffer; GLuint TextureCoordBuffer; - GLuint VAO; - - std::vector> texture; - - Model(const char* path); bool Loadobj( const char* path, @@ -47,8 +58,6 @@ public: std::vector & out_TextureCoords ); - glm::mat4 GetMatrix(); - void CreateBuffers( std::vector _Vertices, std::vector _Normals, diff --git a/Escape-the-Dawn/OBJ.cpp b/Escape-the-Dawn/OBJ.cpp index fb1ae79..4615466 100644 --- a/Escape-the-Dawn/OBJ.cpp +++ b/Escape-the-Dawn/OBJ.cpp @@ -5,13 +5,18 @@ OBJ::OBJ() m_CurrentMaterial = nullptr; } -void OBJ::LoadFromFile(std::string filename) +bool OBJ::LoadFromFile(std::string filename) { m_Path = boost::filesystem::path(filename); - LOG_INFO("Parsing .obj \"%s\"", m_Path.c_str()); // http://paulbourke.net/dataformats/obj/ std::ifstream file(m_Path.string()); + if (!file.is_open()) { + LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str()); + return false; + } + + LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str()); std::string line; while (std::getline(file, line)) { @@ -74,7 +79,7 @@ void OBJ::LoadFromFile(std::string filename) std::string faceDefString; while (ss >> faceDefString) { std::stringstream ss2(faceDefString); - FaceDefinition faceDef = { -1, -1, -1 }; + FaceDefinition faceDef = { 0, 0, 0 }; ss2 >> faceDef.VertexIndex; ss2.ignore(); // Ignore first delimiter @@ -94,13 +99,21 @@ void OBJ::LoadFromFile(std::string filename) Faces.push_back(face); } } + + return true; } void OBJ::ParseMaterial() { // http://paulbourke.net/dataformats/mtl/ std::ifstream file(m_MaterialPath.string()); - + if (!file.is_open()) { + LOG_ERROR("Failed to open .mtl \"%s\"", m_MaterialPath.string().c_str()); + return; + } + + LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str()); + std::string currentMaterialName; MaterialInfo* currentMaterial = nullptr; @@ -130,7 +143,7 @@ void OBJ::ParseMaterial() }; ss >> currentMaterialName; - LOG_INFO("Parsing material %s", currentMaterialName); + LOG_INFO("Parsing material %s", currentMaterialName.c_str()); Materials[currentMaterialName] = mat; currentMaterial = &Materials[currentMaterialName]; continue; diff --git a/Escape-the-Dawn/OBJ.h b/Escape-the-Dawn/OBJ.h index a8f241f..aa157fa 100644 --- a/Escape-the-Dawn/OBJ.h +++ b/Escape-the-Dawn/OBJ.h @@ -51,7 +51,7 @@ public: std::vector Faces; std::map Materials; - void LoadFromFile(std::string filename); + bool LoadFromFile(std::string filename); private: boost::filesystem::path m_Path; diff --git a/Escape-the-Dawn/OpenGL.h b/Escape-the-Dawn/OpenGL.h new file mode 100644 index 0000000..dec332d --- /dev/null +++ b/Escape-the-Dawn/OpenGL.h @@ -0,0 +1,5 @@ +#include +#define GLFW_INCLUDE_GLU +#include +#include +#define GLM_FORCE_RADIANS \ No newline at end of file diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index eff385e..13b93bd 100644 --- a/Escape-the-Dawn/Renderer.cpp +++ b/Escape-the-Dawn/Renderer.cpp @@ -2,6 +2,9 @@ Renderer::Renderer() { + m_VSync = false; + m_DrawNormals = false; + m_DrawWireframe = false; } void Renderer::Initialize() @@ -39,33 +42,63 @@ void Renderer::Initialize() LOG_ERROR("GLEW: Initialization failed"); exit(EXIT_FAILURE); } - glEnable(GL_DEPTH_TEST); - + // Create Camera - m_Camera = std::make_shared(45.f, (float)WIDTH / HEIGHT, 0.01f, 1000.f); m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f)); + glfwSwapInterval(m_VSync); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + LoadContent(); } -void Renderer::Draw(double _dt) +void Renderer::Draw(double dt) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(1.0f, 1.0f, 0.0f, 1.0f); - m_ShaderProgram.Bind(); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +#ifdef DEBUG + glDisable(GL_CULL_FACE); + glPolygonMode(GL_BACK, GL_LINE); +#endif + // Draw models + m_ShaderProgram.Bind(); + glPolygonMode(GL_FRONT_AND_BACK, m_DrawWireframe ? GL_LINE : GL_FILL); + DrawModels(); + +#ifdef DEBUG + // Debug draw normals + if (m_DrawNormals) { + m_ShaderProgramNormals.Bind(); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + DrawModels(); + } +#endif + + ModelsToRender.clear(); + + glfwSwapBuffers(m_Window); +} + +void Renderer::DrawModels() +{ glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); glm::mat4 MVP; - for(int i = 0; i < ModelsToRender.size(); i++) + for (int i = 0; i < ModelsToRender.size(); i++) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, ModelsToRender[i]->model->texture[0]->texture); - MVP = cameraMatrix * ModelsToRender[i]->ModelMatrix; + ModelData* modelData = ModelsToRender.at(i); + auto model = modelData->model; + + MVP = cameraMatrix * modelData->ModelMatrix; glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(ModelsToRender[i]->ModelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelData->ModelMatrix)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data()); glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data()); @@ -74,13 +107,15 @@ void Renderer::Draw(double _dt) glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data()); - glBindVertexArray(ModelsToRender[i]->model->VAO); - glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size()); + + glBindVertexArray(model->VAO); + for (auto texGroup : model->TextureGroups) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture); + glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); + } } - ModelsToRender.clear(); - - glfwSwapBuffers(m_Window); } void Renderer::DrawText() @@ -93,7 +128,7 @@ void Renderer::AddTextToDraw() //Add to draw shit vector } -void Renderer::AddModelToDraw(Model* _model, glm::vec3 _position, glm::quat _orientation) +void Renderer::AddModelToDraw(std::shared_ptr _model, glm::vec3 _position, glm::quat _orientation) { glm::mat4 RotationMatrix = glm::toMat4(_orientation); glm::mat4 ModelMatrix = glm::translate(glm::mat4(), _position) * RotationMatrix ; @@ -130,8 +165,20 @@ void Renderer::AddPointLightToDraw( void Renderer::LoadContent() { - m_ShaderProgram.AddShader(std::unique_ptr(new VertexShader("Shaders/Vertex.glsl"))); - m_ShaderProgram.AddShader(std::unique_ptr(new FragmentShader("Shaders/Fragment.glsl"))); + auto standardVS = std::shared_ptr(new VertexShader("Shaders/Vertex.glsl")); + auto standardFS = std::shared_ptr(new FragmentShader("Shaders/Fragment.glsl")); + + auto normalsGS = std::shared_ptr(new GeometryShader("Shaders/Normals.geo.glsl")); + auto normalsFS = std::shared_ptr(new FragmentShader("Shaders/Normals.frag.glsl")); + + m_ShaderProgram.AddShader(standardVS); + m_ShaderProgram.AddShader(standardFS); m_ShaderProgram.Compile(); m_ShaderProgram.Link(); + + m_ShaderProgramNormals.AddShader(normalsGS); + m_ShaderProgramNormals.AddShader(standardVS); + m_ShaderProgramNormals.AddShader(normalsFS); + m_ShaderProgramNormals.Compile(); + m_ShaderProgramNormals.Link(); } diff --git a/Escape-the-Dawn/Renderer.cpp.orig b/Escape-the-Dawn/Renderer.cpp.orig new file mode 100644 index 0000000..0177d0f --- /dev/null +++ b/Escape-the-Dawn/Renderer.cpp.orig @@ -0,0 +1,193 @@ +#include "Renderer.h" + +Renderer::Renderer() +{ + m_VSync = false; + m_DrawNormals = false; + m_DrawWireframe = false; +} + +void Renderer::Initialize() +{ + // Initialize GLFW + if (!glfwInit()) { + LOG_ERROR("GLFW: Initialization failed"); + exit(EXIT_FAILURE); + } + + // Create a window + WIDTH = 1280; + HEIGHT = 720; + m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr); + if (!m_Window) { + LOG_ERROR("GLFW: Failed to create window"); + exit(EXIT_FAILURE); + } + glfwMakeContextCurrent(m_Window); + + // GL version info + glGetIntegerv(GL_MAJOR_VERSION, &m_glVersion[0]); + glGetIntegerv(GL_MINOR_VERSION, &m_glVersion[1]); + m_glVendor = (GLchar*)glGetString(GL_VENDOR); + std::stringstream ss; + ss << m_glVendor << " OpenGL " << m_glVersion[0] << "." << m_glVersion[1]; +#ifdef DEBUG + ss << " DEBUG"; +#endif + LOG_INFO(ss.str().c_str()); + glfwSetWindowTitle(m_Window, ss.str().c_str()); + + // Initialize GLEW + if (glewInit() != GLEW_OK) { + LOG_ERROR("GLEW: Initialization failed"); + exit(EXIT_FAILURE); + } + + // Create Camera + m_Camera = std::make_shared(45.f, (float)WIDTH / HEIGHT, 0.01f, 1000.f); + m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f)); + + glfwSwapInterval(m_VSync); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + + LoadContent(); +} + +void Renderer::Draw(double dt) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(1.0f, 1.0f, 0.0f, 1.0f); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +#ifdef DEBUG + glDisable(GL_CULL_FACE); + glPolygonMode(GL_BACK, GL_LINE); +#endif + + // Draw models + m_ShaderProgram.Bind(); + glPolygonMode(GL_FRONT_AND_BACK, m_DrawWireframe ? GL_LINE : GL_FILL); + DrawModels(); + +#ifdef DEBUG + // Debug draw normals + if (m_DrawNormals) { + m_ShaderProgramNormals.Bind(); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + DrawModels(); + } +#endif + + ModelsToRender.clear(); + + glfwSwapBuffers(m_Window); +} + +void Renderer::DrawModels() +{ + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); + + glm::mat4 MVP; + for (int i = 0; i < ModelsToRender.size(); i++) + { + ModelData* modelData = ModelsToRender.at(i); + auto model = modelData->model; + + MVP = cameraMatrix * modelData->ModelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelData->ModelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); +<<<<<<< HEAD + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data()); + glBindVertexArray(ModelsToRender[i]->model->VAO); + glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size()); +======= + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "lightPosition"), 1, glm::value_ptr(glm::vec3(2.0f, 4.0f, 1.0f))); + glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 1.5f); + glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 0.0f); + glUniform1f(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 0.0f); +>>>>>>> origin/master + + + glBindVertexArray(model->VAO); + for (auto texGroup : model->TextureGroups) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture); + glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, (texGroup.EndIndex - texGroup.StartIndex + 1) * abs(sin(glfwGetTime()))); + } + } +} + +void Renderer::DrawText() +{ + //DrawShitInTextForm +} + +void Renderer::AddTextToDraw() +{ + //Add to draw shit vector +} + +void Renderer::AddModelToDraw(std::shared_ptr _model, glm::vec3 _position, glm::quat _orientation) +{ + glm::mat4 RotationMatrix = glm::toMat4(_orientation); + glm::mat4 ModelMatrix = glm::translate(glm::mat4(), _position) * RotationMatrix ; + // You can now use ModelMatrix to build the MVP matrix + ModelsToRender.push_back(new ModelData(_model, ModelMatrix)); +} + +void Renderer::AddPointLightToDraw( + glm::vec3 _position, + glm::vec3 _specular, + glm::vec3 _diffuse, + float _constantAttenuation, + float _linearAttenuation, + float _quadraticAttenuation, + float _spotExponent + ) +{ + Light_position.push_back(_position.x); + Light_position.push_back(_position.y); + Light_position.push_back(_position.z); + Light_specular.push_back(_specular.x); + Light_specular.push_back(_specular.y); + Light_specular.push_back(_specular.z); + Light_diffuse.push_back(_diffuse.x); + Light_diffuse.push_back(_diffuse.y); + Light_diffuse.push_back(_diffuse.z); + Light_constantAttenuation.push_back(_constantAttenuation); + Light_linearAttenuation.push_back(_linearAttenuation); + Light_quadraticAttenuation.push_back(_quadraticAttenuation); + Light_spotExponent.push_back(_spotExponent); + +} + + +void Renderer::LoadContent() +{ + auto standardVS = std::shared_ptr(new VertexShader("Shaders/Vertex.glsl")); + auto standardFS = std::shared_ptr(new FragmentShader("Shaders/Fragment.glsl")); + + auto normalsGS = std::shared_ptr(new GeometryShader("Shaders/Normals.geo.glsl")); + auto normalsFS = std::shared_ptr(new FragmentShader("Shaders/Normals.frag.glsl")); + + m_ShaderProgram.AddShader(standardVS); + m_ShaderProgram.AddShader(standardFS); + m_ShaderProgram.Compile(); + m_ShaderProgram.Link(); + + m_ShaderProgramNormals.AddShader(normalsGS); + m_ShaderProgramNormals.AddShader(standardVS); + m_ShaderProgramNormals.AddShader(normalsFS); + m_ShaderProgramNormals.Compile(); + m_ShaderProgramNormals.Link(); +} diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h index 9cc28a4..b75f6bd 100644 --- a/Escape-the-Dawn/Renderer.h +++ b/Escape-the-Dawn/Renderer.h @@ -7,12 +7,7 @@ #include #include -#define _CRT_SECURE_NO_WARNINGS -#include -#define GLFW_INCLUDE_GLU -#include -#include -#define GLM_FORCE_RADIANS +#include "OpenGL.h" #include #include #include @@ -29,7 +24,7 @@ class Renderer { public: - ShaderProgram m_ShaderProgram; + glm::mat4 viewMatrix; glm::mat4 projectionMatrix; @@ -37,10 +32,10 @@ public: struct ModelData { - Model* model; + std::shared_ptr model; glm::mat4 ModelMatrix; - ModelData(Model* _model, glm::mat4 _modelMatrix) : model(_model), ModelMatrix(_modelMatrix) - {} + ModelData(std::shared_ptr _model, glm::mat4 _modelMatrix) + : model(_model), ModelMatrix(_modelMatrix) {} }; std::vector ModelsToRender; @@ -58,7 +53,7 @@ public: void Draw(double dt); void DrawText(); - void AddModelToDraw(Model*, glm::vec3, glm::quat); + void AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation); void AddTextToDraw(); void AddPointLightToDraw( glm::vec3 _position, @@ -75,14 +70,26 @@ public: GLFWwindow* GetWindow() const { return m_Window; } std::shared_ptr GetCamera() const { return m_Camera; } + bool DrawNormals() const { return m_DrawNormals; } + void DrawNormals(bool val) { m_DrawNormals = val; } + bool DrawWireframe() const { return m_DrawWireframe; } + void DrawWireframe(bool val) { m_DrawWireframe = val; } + private: GLFWwindow* m_Window; GLint m_glVersion[2]; GLchar* m_glVendor; + bool m_VSync; + bool m_DrawNormals; + bool m_DrawWireframe; std::shared_ptr m_Camera; - GLuint vertexArrayObject; + ShaderProgram m_ShaderProgram; + ShaderProgram m_ShaderProgramNormals; + + void DrawModels(); + }; #endif // Renderer_h__ \ No newline at end of file diff --git a/Escape-the-Dawn/ShaderProgram.cpp b/Escape-the-Dawn/ShaderProgram.cpp index cd08061..51e8075 100644 --- a/Escape-the-Dawn/ShaderProgram.cpp +++ b/Escape-the-Dawn/ShaderProgram.cpp @@ -84,20 +84,16 @@ bool Shader::IsCompiled() const return m_ShaderHandle != 0; } -ShaderProgram::ShaderProgram() -{ - Initialize(); -} - ShaderProgram::~ShaderProgram() { - Unbind(); - glDeleteProgram(m_ShaderProgramHandle); + if (m_ShaderProgramHandle != 0) { + glDeleteProgram(m_ShaderProgramHandle); + } } -void ShaderProgram::AddShader(std::unique_ptr shader) +void ShaderProgram::AddShader(std::shared_ptr shader) { - m_Shaders.push_back(std::move(shader)); + m_Shaders.push_back(shader); } void ShaderProgram::Compile() @@ -111,6 +107,11 @@ void ShaderProgram::Compile() GLuint ShaderProgram::Link() { + if (m_Shaders.size() == 0) { + LOG_ERROR("Failed to link shader program: No shaders bound"); + return 0; + } + LOG_INFO("Linking shader program"); m_ShaderProgramHandle = glCreateProgram(); for (auto &shader : m_Shaders) { @@ -119,10 +120,6 @@ GLuint ShaderProgram::Link() glLinkProgram(m_ShaderProgramHandle); if (GLERROR("glLinkProgram")) return 0; - - for (auto &shader : m_Shaders) { - shader.release(); - } m_Shaders.clear(); return m_ShaderProgramHandle; @@ -144,9 +141,4 @@ void ShaderProgram::Bind() void ShaderProgram::Unbind() { glActiveShaderProgram(0, 0); -} - -void ShaderProgram::Initialize() -{ - m_ShaderProgramHandle = 0; -} +} \ No newline at end of file diff --git a/Escape-the-Dawn/ShaderProgram.h b/Escape-the-Dawn/ShaderProgram.h index 894575a..341bb64 100644 --- a/Escape-the-Dawn/ShaderProgram.h +++ b/Escape-the-Dawn/ShaderProgram.h @@ -6,11 +6,7 @@ #include #include -#define _CRT_SECURE_NO_WARNINGS -#include -#define GLFW_INCLUDE_GLU -#include -#include +#include "OpenGL.h" #include "glerror.h" @@ -68,25 +64,20 @@ public: class ShaderProgram { public: - ShaderProgram(); + ShaderProgram() + : m_ShaderProgramHandle(0) { } ~ShaderProgram(); - void AddShader(std::unique_ptr shader); - + void AddShader(std::shared_ptr shader); void Compile(); GLuint Link(); - GLuint GetHandle(); - void Bind(); - void Unbind(); private: GLuint m_ShaderProgramHandle; - std::vector> m_Shaders; - - void Initialize(); + std::vector> m_Shaders; }; #endif // ShaderProgram_h__ \ No newline at end of file diff --git a/Escape-the-Dawn/Shaders/Normals.frag.glsl b/Escape-the-Dawn/Shaders/Normals.frag.glsl new file mode 100644 index 0000000..fd1bb9a --- /dev/null +++ b/Escape-the-Dawn/Shaders/Normals.frag.glsl @@ -0,0 +1,9 @@ +#version 430 + +uniform mat4 MVP; + +out vec4 FragmentColor; + +void main() { + FragmentColor = vec4(1.0, 1.0, 1.0, 1.0); +} \ No newline at end of file diff --git a/Escape-the-Dawn/Shaders/Normals.geo.glsl b/Escape-the-Dawn/Shaders/Normals.geo.glsl new file mode 100644 index 0000000..0f72a8e --- /dev/null +++ b/Escape-the-Dawn/Shaders/Normals.geo.glsl @@ -0,0 +1,34 @@ +#version 430 + +uniform mat4 MVP; + +layout(triangles) in; +layout(line_strip, max_vertices = 6) out; + +in VertexData { + vec3 Position; + vec3 Normal; + vec2 TextureCoord; +} Input[3]; + +out VertexData { + vec3 Position; + vec3 Normal; + vec2 TextureCoord; +} Output; + +void main() +{ + for (int i = 0; i < gl_in.length(); i++) + { + gl_Position = MVP * vec4(Input[i].Position, 1.0); + EmitVertex(); + gl_Position = MVP * vec4(Input[i].Position + Input[i].Normal, 1.0); + EmitVertex(); + EndPrimitive(); + + Output.Position = Input[i].Position; + Output.Normal = Input[i].Normal; + Output.TextureCoord = Input[i].TextureCoord; + } +} \ No newline at end of file diff --git a/Escape-the-Dawn/Sounds/hallelujah.wav b/Escape-the-Dawn/Sounds/hallelujah.wav index f103f96..9fc1cb4 100644 Binary files a/Escape-the-Dawn/Sounds/hallelujah.wav and b/Escape-the-Dawn/Sounds/hallelujah.wav differ diff --git a/Escape-the-Dawn/Systems/InputSystem.cpp b/Escape-the-Dawn/Systems/InputSystem.cpp index b6937f7..ef7f17d 100644 --- a/Escape-the-Dawn/Systems/InputSystem.cpp +++ b/Escape-the-Dawn/Systems/InputSystem.cpp @@ -21,9 +21,33 @@ void Systems::InputSystem::Update(double dt) glfwGetCursorPos(m_Renderer->GetWindow(), &xpos, &ypos); m_CurrentMouseDeltaX = xpos - m_LastMouseX; m_CurrentMouseDeltaY = ypos - m_LastMouseY; - m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; - m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; - glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); + m_LastMouseX = xpos; + m_LastMouseY = ypos; + + // Lock mouse while holding LMB + if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; + m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; + glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); + } + // Hide/show cursor with LMB + if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + } + if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); + } + +#ifdef DEBUG + // Wireframe + if (m_CurrentKeyState[GLFW_KEY_F1] && !m_LastKeyState[GLFW_KEY_F1]) { + m_Renderer->DrawWireframe(!m_Renderer->DrawWireframe()); + } + // Normals + if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) { + m_Renderer->DrawNormals(!m_Renderer->DrawNormals()); + } +#endif } void Systems::InputSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -39,3 +63,6 @@ void Systems::InputSystem::UpdateEntity(double dt, EntityID entity, EntityID par input->dX = m_CurrentMouseDeltaX; input->dY = m_CurrentMouseDeltaY; } + +std::array Systems::InputSystem::m_CurrentKeyState; +std::array Systems::InputSystem::m_LastKeyState; diff --git a/Escape-the-Dawn/Systems/InputSystem.h b/Escape-the-Dawn/Systems/InputSystem.h index 73a5946..99cb01f 100644 --- a/Escape-the-Dawn/Systems/InputSystem.h +++ b/Escape-the-Dawn/Systems/InputSystem.h @@ -13,7 +13,7 @@ namespace Systems class InputSystem : public System { public: - InputSystem(World* world, std::shared_ptr renderer) + InputSystem(World* world, std::shared_ptr renderer) : System(world), m_Renderer(renderer) { } void Update(double dt) override; @@ -21,13 +21,13 @@ public: private: std::shared_ptr m_Renderer; - - std::array m_CurrentKeyState; - std::array m_LastKeyState; + static std::array m_CurrentKeyState; + static std::array m_LastKeyState; std::array m_CurrentMouseState; std::array m_LastMouseState; float m_CurrentMouseDeltaX, m_CurrentMouseDeltaY; float m_LastMouseX, m_LastMouseY; + }; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 1e93148..aeb7ca2 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -19,41 +19,44 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa auto name = m_World->GetProperty(entity, "Name"); if (name == "Camera") { + if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) { + glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); + glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); - glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); - glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); - - - float speed = 4.0f; - if(input->KeyState[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS) - { - speed = 1.0f; - } - if(input->KeyState[GLFW_KEY_A] == GLFW_PRESS) - { - transform->Position -= Camera_Right * (float)dt*2.f * speed; - } - if(input->KeyState[GLFW_KEY_D] == GLFW_PRESS) - { - transform->Position += Camera_Right * (float)dt*2.f * speed; - } - if(input->KeyState[GLFW_KEY_W] == GLFW_PRESS) - { - transform->Position -= Camera_Forward * (float)dt*2.f * speed; - } - if(input->KeyState[GLFW_KEY_S] == GLFW_PRESS) - { - transform->Position += Camera_Forward * (float)dt*2.f * speed; - } + float speed = 8.0f; + if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { + speed *= 2.0f; + } + if(input->KeyState[GLFW_KEY_LEFT_ALT]) { + speed /= 2.0f; + } + if(input->KeyState[GLFW_KEY_A]) { + transform->Position -= Camera_Right * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_D]) { + transform->Position += Camera_Right * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_W]) { + transform->Position -= Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_S]) { + transform->Position += Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_SPACE]) { + transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) { + transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed; + } - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - //--------------------------------------------------------------------- - transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + //--------------------------------------------------------------------- + transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; - transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); - //--------------------------------------------------------------------- - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - + transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); + //--------------------------------------------------------------------- + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + } } } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 99efd8b..8058956 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -4,7 +4,6 @@ #include #include "System.h" -#include "Renderer.h" #include "Components/Transform.h" #include "Components/Input.h" #include "logging.h" diff --git a/Escape-the-Dawn/Systems/RenderSystem.cpp b/Escape-the-Dawn/Systems/RenderSystem.cpp index 66961d6..8a7681a 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.cpp +++ b/Escape-the-Dawn/Systems/RenderSystem.cpp @@ -15,14 +15,16 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p auto transformComponent = m_World->GetComponent(entity, "Transform"); if (transformComponent == nullptr) return; + + // Draw models auto modelComponent = m_World->GetComponent(entity, "Model"); if (modelComponent != nullptr) { if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()){ - m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile); - } + m_CachedModels[modelComponent->ModelFile] = std::make_shared(OBJ(modelComponent->ModelFile)); + } - Model* model = m_CachedModels[modelComponent->ModelFile]; + auto model = m_CachedModels[modelComponent->ModelFile]; m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation); } auto pointLightComponent = m_World->GetComponent(entity, "PointLight"); @@ -48,8 +50,6 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip); m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip); } - - } diff --git a/Escape-the-Dawn/Systems/RenderSystem.cpp.orig b/Escape-the-Dawn/Systems/RenderSystem.cpp.orig index 27bfc77..b51a198 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.cpp.orig +++ b/Escape-the-Dawn/Systems/RenderSystem.cpp.orig @@ -7,29 +7,54 @@ void Systems::RenderSystem::OnComponentCreated( std::string type, std:: shared_p { auto modelComponent = std::static_pointer_cast(component); -<<<<<<< HEAD - if (m_CachedModels.find(modelComponent->ModelFile) != m_CachedModels.end()) { - m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile); - } -======= ->>>>>>> ce6b570520794087eb98447a571578585a705ded } } void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) { - auto modelComponent = m_World->GetComponent(entity, "Model"); - if (modelComponent == nullptr) - return; auto transformComponent = m_World->GetComponent(entity, "Transform"); if (transformComponent == nullptr) return; - if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()) { - m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile); + // Draw models + auto modelComponent = m_World->GetComponent(entity, "Model"); + if (modelComponent != nullptr) + { + if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()){ + m_CachedModels[modelComponent->ModelFile] = std::make_shared(OBJ(modelComponent->ModelFile)); + } + + auto model = m_CachedModels[modelComponent->ModelFile]; + m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation); + } +<<<<<<< HEAD + auto pointLightComponent = m_World->GetComponent(entity, "PointLight"); + if (pointLightComponent != nullptr) + { + + m_Renderer->AddPointLightToDraw( + transformComponent->Position, + pointLightComponent->Specular, + pointLightComponent->Diffuse, + pointLightComponent->constantAttenuation, + pointLightComponent->linearAttenuation, + pointLightComponent->quadraticAttenuation, + pointLightComponent->spotExponent); + } +======= + + // Update camera +>>>>>>> origin/master + auto cameraComponent = m_World->GetComponent(entity, "Camera"); + if (cameraComponent != nullptr) + { + m_Renderer->GetCamera()->Position(transformComponent->Position); + m_Renderer->GetCamera()->Orientation(transformComponent->Orientation); + + m_Renderer->GetCamera()->FOV(cameraComponent->FOV); + m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip); + m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip); } - Model* model = m_CachedModels[modelComponent->ModelFile]; - m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation); } diff --git a/Escape-the-Dawn/Systems/RenderSystem.h b/Escape-the-Dawn/Systems/RenderSystem.h index fab25ea..086a54a 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.h +++ b/Escape-the-Dawn/Systems/RenderSystem.h @@ -1,6 +1,8 @@ #ifndef RenderSystem_h__ #define RenderSystem_h__ +#include + #include "System.h" #include "Model.h" #include "Texture.h" @@ -8,7 +10,6 @@ #include "Components/Transform.h" #include "Components/Camera.h" #include "Renderer.h" -#include namespace Systems { @@ -19,7 +20,7 @@ namespace Systems RenderSystem(World* world, std::shared_ptr renderer) : System(world), m_Renderer(renderer) {} - std::unordered_map m_CachedModels; + std::unordered_map> m_CachedModels; void OnComponentCreated(std::string type, std:: shared_ptr component) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; diff --git a/Escape-the-Dawn/Texture.cpp b/Escape-the-Dawn/Texture.cpp index 8fa587c..de050c7 100644 --- a/Escape-the-Dawn/Texture.cpp +++ b/Escape-the-Dawn/Texture.cpp @@ -1,14 +1,14 @@ #include "Texture.h" -Texture::Texture( const char* path ) +Texture::Texture(std::string path) { Load(path); } -void Texture::Load( const char* path ) +void Texture::Load(std::string path) { - texture = SOIL_load_OGL_texture(path, 0, 0, SOIL_FLAG_INVERT_Y); + texture = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y); } void Texture::Bind() diff --git a/Escape-the-Dawn/Texture.h b/Escape-the-Dawn/Texture.h index bf27ff3..f24cb2f 100644 --- a/Escape-the-Dawn/Texture.h +++ b/Escape-the-Dawn/Texture.h @@ -1,22 +1,21 @@ #ifndef Texture_h__ #define Texture_h__ -#include -#define GLFW_INCLUDE_GLU -#include -#include +#include + +#include "OpenGL.h" #include class Texture { public: - Texture(const char* path); + Texture(std::string path); ~Texture(); GLuint texture; - void Load(const char* path); + void Load(std::string path); void Bind(); }; diff --git a/Escape-the-Dawn/World.h b/Escape-the-Dawn/World.h index 0e1a652..009c768 100644 --- a/Escape-the-Dawn/World.h +++ b/Escape-the-Dawn/World.h @@ -6,6 +6,7 @@ #include #include #include +#include #include diff --git a/Escape-the-Dawn/glerror.h b/Escape-the-Dawn/glerror.h index 88f58a7..42432e4 100644 --- a/Escape-the-Dawn/glerror.h +++ b/Escape-the-Dawn/glerror.h @@ -1,8 +1,6 @@ #ifndef _GLERROR_H #define _GLERROR_H -#define GLFW_INCLUDE_GLU -#include #include #include "logging.h" diff --git a/Executable/main.cpp b/Escape-the-Dawn/main.cpp similarity index 100% rename from Executable/main.cpp rename to Escape-the-Dawn/main.cpp diff --git a/Executable/Executable.vcxproj b/Executable/Executable.vcxproj deleted file mode 100644 index 55c1a25..0000000 --- a/Executable/Executable.vcxproj +++ /dev/null @@ -1,93 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {A9755CAA-62DC-442D-B82C-F548546CFD38} - Executable - - - - Application - true - v110 - MultiByte - - - Application - false - v110 - true - MultiByte - - - - - - - - - - - - - $(SolutionDir)\Escape-the-Dawn;$(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) - $(SolutionDir)bin\ - $(SolutionName)-$(Configuration) - $(SolutionDir)obj\$(ProjectName)\ - $(BOOST_ROOT)\lib32-msvc-11.0;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSDK_LibraryPath_x86); - - - $(SolutionDir)\Escape-the-Dawn;$(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) - $(SolutionDir)bin\ - $(SolutionName)-$(Configuration) - $(SolutionDir)obj\$(ProjectName)\ - $(BOOST_ROOT)\lib32-msvc-11.0;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSDK_LibraryPath_x86); - - - - Level3 - Disabled - true - GLEW_STATIC;_CRT_SECURE_NO_WARNINGS;DEBUG;_MBCS;%(PreprocessorDefinitions) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - GLEW_STATIC;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions) - - - true - true - true - - - - - - - - {fe405cfa-8fce-4867-92cf-797e73b36482} - - - - - - \ No newline at end of file diff --git a/Executable/Executable.vcxproj.filters b/Executable/Executable.vcxproj.filters deleted file mode 100644 index 8755a3a..0000000 --- a/Executable/Executable.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/Libraries/glew-1.10.0/lib/Release/Win32/glew32s.lib b/Libraries/glew-1.10.0/lib/Release/Win32/glew32s.lib index 660a427..5beb729 100644 Binary files a/Libraries/glew-1.10.0/lib/Release/Win32/glew32s.lib and b/Libraries/glew-1.10.0/lib/Release/Win32/glew32s.lib differ diff --git a/Tests/Debug/boost_unit_test_framework-vc110-gd-1_55.dll b/Tests/Debug/boost_unit_test_framework-vc110-gd-1_55.dll deleted file mode 100644 index 548d50c..0000000 Binary files a/Tests/Debug/boost_unit_test_framework-vc110-gd-1_55.dll and /dev/null differ diff --git a/Tests/Release/boost_unit_test_framework-vc110-1_55.dll b/Tests/Release/boost_unit_test_framework-vc110-1_55.dll deleted file mode 100644 index 492bd71..0000000 Binary files a/Tests/Release/boost_unit_test_framework-vc110-1_55.dll and /dev/null differ diff --git a/Tests/Tests.vcxproj b/Tests/Tests.vcxproj deleted file mode 100644 index 18b7ec3..0000000 --- a/Tests/Tests.vcxproj +++ /dev/null @@ -1,107 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {B9A8F4AA-BE85-45EA-84DD-652D13DD22BE} - Tests - - - - Application - true - v110 - MultiByte - - - Application - false - v110 - true - MultiByte - - - - - - - - - - - - - $(SolutionDir)\Escape-the-Dawn;$(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) - $(BOOST_ROOT)\lib32-msvc-11.0;$(LibraryPath) - $(ProjectDir)$(Configuration)\ - $(SolutionDir)obj\$(ProjectName)\ - - - $(SolutionDir)\Escape-the-Dawn;$(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) - $(BOOST_ROOT)\lib32-msvc-11.0;$(LibraryPath) - $(ProjectDir)$(Configuration)\ - $(SolutionDir)obj\$(ProjectName)\ - - - - Level3 - Disabled - true - - - true - Console - boost_unit_test_framework-vc110-gd-1_55.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - - "$(OutDir)$(TargetName)$(TargetExt)" --log_level=test_suite - - - Running tests - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - boost_unit_test_framework-vc110-1_55.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - "$(OutDir)$(TargetName)$(TargetExt)" --log_level=test_suite - - - Running tests - - - - - - - - {fe405cfa-8fce-4867-92cf-797e73b36482} - - - - - - \ No newline at end of file diff --git a/Tests/Tests.vcxproj.filters b/Tests/Tests.vcxproj.filters deleted file mode 100644 index 8755a3a..0000000 --- a/Tests/Tests.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/Tests/main.cpp b/Tests/main.cpp deleted file mode 100644 index fdbaa18..0000000 --- a/Tests/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "logging.h" - -#include "World.h" -#include "GameWorld.h" -#include "Components/Transform.h" - -#define BOOST_TEST_MODULE World -#define BOOST_TEST_DYN_LINK -#include - -BOOST_AUTO_TEST_CASE(Parenting) -{ - World world; - - // Parenting - EntityID ent1 = world.CreateEntity(); - BOOST_CHECK(ent1 != 0); // 0 is reserved for world - BOOST_CHECK(ent1 == 1); - BOOST_CHECK(world.GetEntityParent(ent1) == 0); - EntityID ent2 = world.CreateEntity(ent1); - BOOST_CHECK(ent2 != 0); - BOOST_CHECK(ent2 == ent1 + 1); - BOOST_CHECK(world.GetEntityParent(ent2) == ent1); -} - -BOOST_AUTO_TEST_CASE(SceneGraphTraversal) -{ - std::shared_ptr renderer(new Renderer()); - renderer->Initialize(); - GameWorld world(renderer); - - EntityID ent1 = world.CreateEntity(); - auto t1 = world.AddComponent(ent1, "Transform"); - BOOST_REQUIRE(t1 != nullptr); - t1->Position[0] = 1.0f; - t1->Position[1] = 1.0f; - t1->Position[2] = 1.0f; - EntityID ent2 = world.CreateEntity(ent1); - auto t2 = world.AddComponent(ent2, "Transform"); - BOOST_REQUIRE(t2 != nullptr); - t2->Position[0] = 1.0f; - t2->Position[1] = 1.0f; - t2->Position[2] = 1.0f; - - world.Update(0.0); - - LOG_INFO("ent1: %f %f %f", t1->Position[0], t1->Position[1], t1->Position[2]); - LOG_INFO("ent2: %f %f %f", t2->Position[0], t2->Position[1], t2->Position[2]); -} - -BOOST_AUTO_TEST_CASE(Recycling) -{ - World world; - - // EntityID recycling - EntityID ent11 = world.CreateEntity(); // 1 - world.RemoveEntity(ent11); - EntityID ent12 = world.CreateEntity(); // 1 - BOOST_REQUIRE(ent11 == ent12); -} - -BOOST_AUTO_TEST_CASE(ComponentCreation) -{ - World world; - - EntityID ent = world.CreateEntity(); - BOOST_CHECK(world.AddComponent(ent, "Transform") != nullptr); - BOOST_CHECK(world.AddComponent(ent, "Input") != nullptr); -} - -BOOST_AUTO_TEST_CASE(Properties) -{ - World world; - - EntityID ent = world.CreateEntity(); - - world.SetProperty(ent, "String", std::string("derpfish")); - world.SetProperty(ent, "Integer", 123); - world.SetProperty(ent, "Float", 0.04f); - - BOOST_CHECK(world.GetProperty(ent, "String") == "derpfish"); - BOOST_CHECK(world.GetProperty(ent, "Integer") == 123); - BOOST_CHECK(world.GetProperty(ent, "Float") == 0.04f); -} \ No newline at end of file