Add drawing HUD HP bar

This commit is contained in:
s473577 2024-02-01 23:27:42 +01:00
parent de13bc43a4
commit 94b22aad78
3 changed files with 25 additions and 0 deletions

View File

@ -12,6 +12,25 @@ Core::SpriteRenderer::~SpriteRenderer()
glDeleteBuffers(1, &this->VBO);
glDeleteBuffers(1, &this->EBO);
}
void Core::SpriteRenderer::DrawHUDBar(const glm::vec3 color, const glm::mat4 modelMatrix, const float progress, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
// Kombinuj macierze transformacji
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
// Przeka¿ macierze do shadera
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniform3fv(glGetUniformLocation(program, "activeColor"), 1, glm::value_ptr(color));
glUniform1f(glGetUniformLocation(program, "progress"), progress);
glBindVertexArray(this->VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
};
void Core::SpriteRenderer::DrawSpriteBar(const glm::vec3 color, const glm::mat4 modelMatrix,const float progress, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();

View File

@ -11,6 +11,7 @@ namespace Core {
~SpriteRenderer();
void DrawSprite(GLuint spriteTexture, const glm::mat4 modelMatrix, GLuint program);
void DrawSpriteBar(const glm::vec3 color, const glm::mat4 modelMatrix,const float progress, GLuint program);
void DrawHUDBar(const glm::vec3 color, const glm::mat4 modelMatrix, const float progress, GLuint program);
private:
unsigned int VAO;

View File

@ -95,7 +95,12 @@ void updateDeltaTime(float time) {
lastTime = time;
}
void renderEnemies() {
glDisable(GL_DEPTH_TEST);
glUseProgram(programSpriteBar);
glm::mat4 spaceshipModelMatrix = spaceship->calculateModelMatrix();
glm::mat4 healthBarPosition = glm::translate(spaceshipModelMatrix, glm::vec3(12.0f, -9.0f, 0.0f));
spriteRenderer->DrawHUDBar(glm::vec3(0.0f, 1.0f, 0.0f), glm::scale(healthBarPosition, glm::vec3(9.0f, 1.1f, 1.0f)), 1.f, programSpriteBar);
glEnable(GL_DEPTH_TEST);
for (const auto& enemy : enemies) {
if (enemy->isAlive()) {
spriteRenderer->DrawSpriteBar(