Fix healthbar is visible in maximized window

This commit is contained in:
s473577 2024-02-07 15:35:59 +01:00
parent 2063395cea
commit 95988104a1

View File

@ -103,15 +103,24 @@ void updateDeltaTime(float time) {
if (deltaTime > 0.1) deltaTime = 0.1; if (deltaTime > 0.1) deltaTime = 0.1;
lastTime = time; 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); glUseProgram(programSpriteBar);
glDisable(GL_DEPTH_TEST); 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( spriteRenderer->DrawHUDBar(
glm::vec3(0.0f, 1.0f, 0.0f), 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, spaceship->currentHP / spaceship->maxHP,
programSpriteBar); programSpriteBar);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -238,7 +247,7 @@ void renderScene(GLFWwindow* window)
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time); spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
renderHUD(); renderHUD(window);
renderEnemies(); 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); //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);