Add drawing HUD HP bar
This commit is contained in:
parent
de13bc43a4
commit
94b22aad78
@ -12,6 +12,25 @@ Core::SpriteRenderer::~SpriteRenderer()
|
|||||||
glDeleteBuffers(1, &this->VBO);
|
glDeleteBuffers(1, &this->VBO);
|
||||||
glDeleteBuffers(1, &this->EBO);
|
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) {
|
void Core::SpriteRenderer::DrawSpriteBar(const glm::vec3 color, const glm::mat4 modelMatrix,const float progress, GLuint program) {
|
||||||
|
|
||||||
Spaceship* spaceship = Spaceship::getInstance();
|
Spaceship* spaceship = Spaceship::getInstance();
|
||||||
|
@ -11,6 +11,7 @@ namespace Core {
|
|||||||
~SpriteRenderer();
|
~SpriteRenderer();
|
||||||
void DrawSprite(GLuint spriteTexture, const glm::mat4 modelMatrix, GLuint program);
|
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 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:
|
private:
|
||||||
|
|
||||||
unsigned int VAO;
|
unsigned int VAO;
|
||||||
|
@ -95,7 +95,12 @@ void updateDeltaTime(float time) {
|
|||||||
lastTime = time;
|
lastTime = time;
|
||||||
}
|
}
|
||||||
void renderEnemies() {
|
void renderEnemies() {
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
glUseProgram(programSpriteBar);
|
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) {
|
for (const auto& enemy : enemies) {
|
||||||
if (enemy->isAlive()) {
|
if (enemy->isAlive()) {
|
||||||
spriteRenderer->DrawSpriteBar(
|
spriteRenderer->DrawSpriteBar(
|
||||||
|
Loading…
Reference in New Issue
Block a user