diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index d237d2d..1f6bef8 100644 --- a/Escape-the-Dawn/Renderer.cpp +++ b/Escape-the-Dawn/Renderer.cpp @@ -3,8 +3,15 @@ Renderer::Renderer() { m_VSync = false; +#ifdef DEBUG m_DrawNormals = false; m_DrawWireframe = false; + m_DrawBounds = true; +#else + m_DrawNormals = false; + m_DrawWireframe = false; + m_DrawBounds = false; +#endif m_ShadowMapRes = 2048*2; m_SunPosition = glm::vec3(0, 0.3f, 10); @@ -131,27 +138,29 @@ void Renderer::Draw(double dt) #ifdef DEBUG // Draw bounding boxes - glEnable(GL_BLEND); - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - m_ShaderProgramDebugAABB.Bind(); - for (auto tuple : AABBsToRender) { - glm::mat4 modelMatrix; - bool colliding; - std::tie(modelMatrix, colliding) = tuple; - // Model matrix - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); - glm::mat4 MVP = cameraMatrix * modelMatrix; - glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - // Color - glm::vec4 color(1.f, 1.f, 1.f, 0.f); - if (colliding) - color = glm::vec4(1.f, 0.f, 0.f, 0.f); - glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color)); - glBindVertexArray(m_DebugAABB); - glDrawArrays(GL_LINES, 0, 24); + if (m_DrawBounds) { + glEnable(GL_BLEND); + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); + m_ShaderProgramDebugAABB.Bind(); + for (auto tuple : AABBsToRender) { + glm::mat4 modelMatrix; + bool colliding; + std::tie(modelMatrix, colliding) = tuple; + // Model matrix + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); + glm::mat4 MVP = cameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // Color + glm::vec4 color(1.f, 1.f, 1.f, 0.f); + if (colliding) + color = glm::vec4(1.f, 0.f, 0.f, 0.f); + glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color)); + glBindVertexArray(m_DebugAABB); + glDrawArrays(GL_LINES, 0, 24); + } } - DrawDebugShadowMap(); + //DrawDebugShadowMap(); #endif ClearStuff(); diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h index c02787d..2c4c492 100644 --- a/Escape-the-Dawn/Renderer.h +++ b/Escape-the-Dawn/Renderer.h @@ -69,6 +69,8 @@ public: void DrawNormals(bool val) { m_DrawNormals = val; } bool DrawWireframe() const { return m_DrawWireframe; } void DrawWireframe(bool val) { m_DrawWireframe = val; } + bool DrawBounds() const { return m_DrawBounds; } + void DrawBounds(bool val) { m_DrawBounds = val; } private: GLFWwindow* m_Window; @@ -77,6 +79,7 @@ private: bool m_VSync; bool m_DrawNormals; bool m_DrawWireframe; + bool m_DrawBounds; int m_ShadowMapRes; glm::vec3 m_SunPosition; diff --git a/Escape-the-Dawn/Systems/InputSystem.cpp b/Escape-the-Dawn/Systems/InputSystem.cpp index ef7f17d..495cc55 100644 --- a/Escape-the-Dawn/Systems/InputSystem.cpp +++ b/Escape-the-Dawn/Systems/InputSystem.cpp @@ -47,6 +47,10 @@ void Systems::InputSystem::Update(double dt) if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) { m_Renderer->DrawNormals(!m_Renderer->DrawNormals()); } + // Bounds + if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) { + m_Renderer->DrawBounds(!m_Renderer->DrawBounds()); + } #endif } diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index 673a4e6..e5cdb3c 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -77,6 +77,9 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par void Systems::SoundSystem::PlaySound(std::shared_ptr emitter, std::string fileName) { + if (m_Sources.find(emitter.get()) == m_Sources.end()) + return; + ALuint buffer = LoadFile(fileName); ALuint source = m_Sources[emitter.get()]; alSourcei(source, AL_BUFFER, buffer);