@@ -45,7 +45,6 @@ namespace gameplay {
4545 weaponMaterial->pipelineState .blending .sourceFactor = GL_SRC_ALPHA ;
4646 weaponMaterial->pipelineState .blending .destinationFactor = GL_ONE_MINUS_SRC_ALPHA ;
4747
48- textRenderer.initialize ();
4948 testFont.load (fontPath, fontTexturePath);
5049 }
5150
@@ -76,7 +75,7 @@ namespace gameplay {
7675 fontTexturePath = data.value (" fontTexturePath" , fontTexturePath);
7776 }
7877
79- void PlayerHUDSystem::render (our::World* world, our::Entity* playerEntity, glm::ivec2 windowSize) {
78+ void PlayerHUDSystem::render (our::World* world, our::Entity* playerEntity, glm::ivec2 windowSize, our::TextRenderer* textRenderer ) {
8079 if (!playerEntity) return ;
8180
8281 HealthComponent* playerHealth = playerEntity->getComponent <HealthComponent>();
@@ -126,25 +125,27 @@ namespace gameplay {
126125 }
127126
128127 // Ammo Counter
129- std::string ammoText = std::to_string (playerComp->currentAmmo ) + " -" + std::to_string (playerComp->maxAmmo );
130-
131- glm::vec4 outlineColor = glm::vec4 (0 .0f , 0 .0f , 0 .0f , 1 .0f );
132-
133- // PS2 ahh way to make outline, I can't find a solution to balance outline with scale, this is good enough :)
134- // (draws the text blackened four times to create an outline)
135- our::UIRect tr = ammoTextRect; tr.offset += glm::vec2 (outlineSpread, outlineSpread);
136- textRenderer.drawText (&testFont, ammoText, tr, windowSize, textScale, orthoVP, outlineColor);
137-
138- our::UIRect bl = ammoTextRect; bl.offset += glm::vec2 (-outlineSpread, -outlineSpread);
139- textRenderer.drawText (&testFont, ammoText, bl, windowSize, textScale, orthoVP, outlineColor);
140-
141- our::UIRect tl = ammoTextRect; tl.offset += glm::vec2 (-outlineSpread, outlineSpread);
142- textRenderer.drawText (&testFont, ammoText, tl, windowSize, textScale, orthoVP, outlineColor);
143-
144- our::UIRect br = ammoTextRect; br.offset += glm::vec2 (outlineSpread, -outlineSpread);
145- textRenderer.drawText (&testFont, ammoText, br, windowSize, textScale, orthoVP, outlineColor);
146-
147- textRenderer.drawText (&testFont, ammoText, ammoTextRect, windowSize, textScale, orthoVP, ammoColor);
128+ if (textRenderer) {
129+ std::string ammoText = std::to_string (playerComp->currentAmmo ) + " -" + std::to_string (playerComp->maxAmmo );
130+
131+ glm::vec4 outlineColor = glm::vec4 (0 .0f , 0 .0f , 0 .0f , 1 .0f );
132+
133+ // PS2 ahh way to make outline, I can't find a solution to balance outline with scale, this is good enough :)
134+ // (draws the text blackened four times to create an outline)
135+ our::UIRect tr = ammoTextRect; tr.offset += glm::vec2 (outlineSpread, outlineSpread);
136+ textRenderer->drawText (&testFont, ammoText, tr, windowSize, textScale, orthoVP, outlineColor);
137+
138+ our::UIRect bl = ammoTextRect; bl.offset += glm::vec2 (-outlineSpread, -outlineSpread);
139+ textRenderer->drawText (&testFont, ammoText, bl, windowSize, textScale, orthoVP, outlineColor);
140+
141+ our::UIRect tl = ammoTextRect; tl.offset += glm::vec2 (-outlineSpread, outlineSpread);
142+ textRenderer->drawText (&testFont, ammoText, tl, windowSize, textScale, orthoVP, outlineColor);
143+
144+ our::UIRect br = ammoTextRect; br.offset += glm::vec2 (outlineSpread, -outlineSpread);
145+ textRenderer->drawText (&testFont, ammoText, br, windowSize, textScale, orthoVP, outlineColor);
146+
147+ textRenderer->drawText (&testFont, ammoText, ammoTextRect, windowSize, textScale, orthoVP, ammoColor);
148+ }
148149 }
149150
150151 void PlayerHUDSystem::destroy () {
@@ -158,7 +159,6 @@ namespace gameplay {
158159 delete weaponMaterial;
159160 }
160161
161- textRenderer.destroy ();
162162 testFont.destroy ();
163163 }
164164
0 commit comments