diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index 617484e..eed646b 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,13 +42,16 @@ 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(); } @@ -54,12 +60,25 @@ 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 - m_ShaderProgramNormals.Bind(); - DrawModels(); + // Debug draw normals + if (m_DrawNormals) { + m_ShaderProgramNormals.Bind(); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + DrawModels(); + } #endif ModelsToRender.clear(); diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h index 9dd1c2c..a0f838e 100644 --- a/Escape-the-Dawn/Renderer.h +++ b/Escape-the-Dawn/Renderer.h @@ -53,10 +53,18 @@ 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; diff --git a/Escape-the-Dawn/ShaderProgram.cpp b/Escape-the-Dawn/ShaderProgram.cpp index d95aeeb..51e8075 100644 --- a/Escape-the-Dawn/ShaderProgram.cpp +++ b/Escape-the-Dawn/ShaderProgram.cpp @@ -86,13 +86,14 @@ bool Shader::IsCompiled() const ShaderProgram::~ShaderProgram() { - Unbind(); - glDeleteProgram(m_ShaderProgramHandle); + if (m_ShaderProgramHandle != 0) { + glDeleteProgram(m_ShaderProgramHandle); + } } void ShaderProgram::AddShader(std::shared_ptr shader) { - m_Shaders.push_back(std::move(shader)); + m_Shaders.push_back(shader); } void ShaderProgram::Compile() @@ -108,6 +109,7 @@ 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"); diff --git a/Escape-the-Dawn/Systems/InputSystem.cpp b/Escape-the-Dawn/Systems/InputSystem.cpp index b6937f7..81f8f15 100644 --- a/Escape-the-Dawn/Systems/InputSystem.cpp +++ b/Escape-the-Dawn/Systems/InputSystem.cpp @@ -24,6 +24,17 @@ void Systems::InputSystem::Update(double dt) m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); + +#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 +50,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; + }; }