From 95988104a12c02b7ccc4402cafcc41b1d2c90798 Mon Sep 17 00:00:00 2001 From: s473577 Date: Wed, 7 Feb 2024 15:35:59 +0100 Subject: [PATCH] Fix healthbar is visible in maximized window --- grk/project/src/ex_9_1.hpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index f7ad488..930397d 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -103,15 +103,24 @@ void updateDeltaTime(float time) { if (deltaTime > 0.1) deltaTime = 0.1; lastTime = time; } -void renderHUD() { - +void renderHUD(GLFWwindow* window) { + glm::mat4 modelMatrixHUD = spaceship->calculateModelMatrixForHUDBar(); + glm::mat4 healthBarPosition; + glm::vec3 healthBarScale; + if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { + healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -11.0f, 0.0f)); + healthBarScale = glm::vec3(22.0f, 2.f, 1.0f); + } + else { + healthBarScale = glm::vec3(22.0f, 4.f, 1.0f); + healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -30.0f, 0.0f)); + } glUseProgram(programSpriteBar); glDisable(GL_DEPTH_TEST); - glm::mat4 modelMatrixHUD = spaceship->calculateModelMatrixForHUDBar(); - glm::mat4 healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -35.0f, 0.0f)); + spriteRenderer->DrawHUDBar( glm::vec3(0.0f, 1.0f, 0.0f), - glm::scale(healthBarPosition, glm::vec3(22.0f, 4.f, 1.0f)), + glm::scale(healthBarPosition, healthBarScale), spaceship->currentHP / spaceship->maxHP, programSpriteBar); glEnable(GL_DEPTH_TEST); @@ -238,7 +247,7 @@ void renderScene(GLFWwindow* window) spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time); - renderHUD(); + renderHUD(window); renderEnemies(); //drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);