ADD: Remove UiTexts from Rendering and only use GuiTextRendering

This commit is contained in:
sebastian 2026-02-15 16:56:49 +01:00
parent 9ef692ab5d
commit 968485ec1b
11 changed files with 11 additions and 98 deletions

View File

@ -134,8 +134,8 @@ add_executable(Dicewars_Siedler src/main.cpp
src/engine/core/gui/uiComponent/UiText.h src/engine/core/gui/uiComponent/UiText.h
src/engine/core/gui/text/Font.cpp src/engine/core/gui/text/Font.cpp
src/engine/core/gui/text/Font.h src/engine/core/gui/text/Font.h
src/engine/core/gui/uiComponent/UiRenderBundle.cpp src/engine/renderer/components/UiRenderBundle.cpp
src/engine/core/gui/uiComponent/UiRenderBundle.h src/engine/renderer/components/UiRenderBundle.h
src/engine/renderer/shaders/TextShader.cpp src/engine/renderer/shaders/TextShader.cpp
src/engine/renderer/shaders/TextShader.h src/engine/renderer/shaders/TextShader.h
src/engine/renderer/TextRenderer.cpp src/engine/renderer/TextRenderer.cpp

View File

@ -8,7 +8,7 @@
#include <vector> #include <vector>
#include "layout/UiPositioner.h" #include "layout/UiPositioner.h"
#include "UiRenderBundle.h" #include "../../../renderer/components/UiRenderBundle.h"
#include "../../../renderer/model/GUITexture.h" #include "../../../renderer/model/GUITexture.h"
enum class UiElementState { enum class UiElementState {

View File

@ -22,9 +22,6 @@ void UiText::setText(const std::string &text) {
void UiText::onCollectRenderData(UiRenderBundle& ui_render_bundle) { void UiText::onCollectRenderData(UiRenderBundle& ui_render_bundle) {
if (!visible) return; if (!visible) return;
if (this->text == "Runde: 0") { GUIText guiText = GUIText(font, text, uiPositioner.screenSpace);
printf("Runde: 0\n"); ui_render_bundle.addGUIText(std::make_shared<GUIText>(guiText));
}
ui_render_bundle.addText(this);
} }

View File

@ -5,7 +5,7 @@
#ifndef DICEWARS_SIEDLER_UITEXT_H #ifndef DICEWARS_SIEDLER_UITEXT_H
#define DICEWARS_SIEDLER_UITEXT_H #define DICEWARS_SIEDLER_UITEXT_H
#include "UiComponent.h" #include "UiComponent.h"
#include "UiRenderBundle.h" #include "../../../renderer/components/UiRenderBundle.h"
#include "glm/vec3.hpp" #include "glm/vec3.hpp"
class Font; class Font;

View File

@ -7,7 +7,7 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "../core/gui/uiComponent/UiRenderBundle.h" #include "components/UiRenderBundle.h"
#include "../toolbox/MathUtils.h" #include "../toolbox/MathUtils.h"
#include "loader/Loader.h" #include "loader/Loader.h"

View File

@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "../core/gui/uiComponent/UiRenderBundle.h" #include "components/UiRenderBundle.h"
#include "model/GUITexture.h" #include "model/GUITexture.h"
#include "model/RawModel.h" #include "model/RawModel.h"
#include "shaders/GUIShader.h" #include "shaders/GUIShader.h"

View File

@ -9,74 +9,6 @@
#include "../core/gui/text/Font.h" #include "../core/gui/text/Font.h"
#include "glm/ext/matrix_clip_space.hpp" #include "glm/ext/matrix_clip_space.hpp"
void TextRenderer::renderTexts(const std::vector<UiText*> &textsToRender) {
shader.start();
shader.loadProjectionMatrix(calculateOrthographicProjectionMatrix());
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (const auto &text : textsToRender) {
renderText(*text);
}
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
shader.stop();
}
void TextRenderer::renderText(const UiText &textToRender) {
const Dimensions& d = textToRender.uiPositioner.screenSpace;
const Font& font = textToRender.getFont();
const std::string& text = textToRender.getText();
float screenX = d.x * Application::getInstance().getWindow().GetWidth();
float screenY = (1.f - d.y) * Application::getInstance().getWindow().GetHeight();
float x = screenX;
float y = screenY - font.getLineHeight();
float scale = 1.0f;
shader.loadTextColor(textToRender.getColor());
for (char c : text) {
const Font::Character& ch = font.getCharacter(c);
float xpos = x + static_cast<float>(ch.bearing.x) * scale;
float ypos = y - static_cast<float>(ch.size.y - ch.bearing.y) * scale;
float w = static_cast<float>(ch.size.x) * scale;
float h = static_cast<float>(ch.size.y) * scale;
float vertices[6][4] = {
{ xpos, ypos + h, 0.0f, 0.0f },
{ xpos, ypos, 0.0f, 1.0f },
{ xpos + w, ypos, 1.0f, 1.0f },
{ xpos, ypos + h, 0.0f, 0.0f },
{ xpos + w, ypos, 1.0f, 1.0f },
{ xpos + w, ypos + h, 1.0f, 0.0f }
};
glBindVertexArray(textModel.vaoID);
glEnableVertexAttribArray(0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ch.textureID);
glBindBuffer(GL_ARRAY_BUFFER, textModel.vboID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
glDrawArrays(GL_TRIANGLES, 0, 6);
x+= static_cast<float>(ch.advance >> 6) * scale;
glBindVertexArray(0);
glDisableVertexAttribArray(0);
}
glBindTexture(GL_TEXTURE_2D, 0);
}
void TextRenderer::renderGuiTexts(const std::vector<std::shared_ptr<GUIText>> &texts) { void TextRenderer::renderGuiTexts(const std::vector<std::shared_ptr<GUIText>> &texts) {
shader.start(); shader.start();
shader.loadProjectionMatrix(calculateOrthographicProjectionMatrix()); shader.loadProjectionMatrix(calculateOrthographicProjectionMatrix());

View File

@ -16,10 +16,6 @@
class TextRenderer { class TextRenderer {
public: public:
TextRenderer() : textModel(Loader::instance().loadTextModel()) {}; TextRenderer() : textModel(Loader::instance().loadTextModel()) {};
void renderTexts(const std::vector<UiText *> &textsToRender);
void renderText(const UiText &textToRender);
void renderGuiTexts(const std::vector<std::shared_ptr<GUIText>> & texts); void renderGuiTexts(const std::vector<std::shared_ptr<GUIText>> & texts);
void renderGuiText(const GUIText& text); void renderGuiText(const GUIText& text);

View File

@ -7,18 +7,14 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "../../../renderer/model/GUIText.h" #include "../model/GUIText.h"
class UiText; class UiText;
#include "../../../renderer/model/GUITexture.h" #include "../model/GUITexture.h"
class UiRenderBundle { class UiRenderBundle {
public: public:
void addText(UiText* text) {
texts.push_back(text);
}
void addGUITexture(const std::shared_ptr<GUITexture>& guiTexture) { void addGUITexture(const std::shared_ptr<GUITexture>& guiTexture) {
guiImages.push_back(guiTexture); guiImages.push_back(guiTexture);
} }
@ -27,10 +23,6 @@ public:
return guiImages; return guiImages;
} }
std::vector<UiText*> getTexts() {
return texts;
}
void addGUIText(const std::shared_ptr<GUIText>& guiText) { void addGUIText(const std::shared_ptr<GUIText>& guiText) {
guiTexts.push_back(guiText); guiTexts.push_back(guiText);
} }
@ -41,7 +33,6 @@ public:
private: private:
std::vector<std::shared_ptr<GUITexture>> guiImages; std::vector<std::shared_ptr<GUITexture>> guiImages;
std::vector<UiText*> texts;
std::vector<std::shared_ptr<GUIText>> guiTexts; std::vector<std::shared_ptr<GUIText>> guiTexts;

View File

@ -151,9 +151,6 @@ void UILayer::onUpdate() {
auto guis = renderBundle.getGUITextures(); auto guis = renderBundle.getGUITextures();
guiRenderer->render(guis); guiRenderer->render(guis);
auto texts = renderBundle.getTexts();
textRenderer->renderTexts(texts);
auto renderTexts = renderBundle.getGUITexts(); auto renderTexts = renderBundle.getGUITexts();
textRenderer->renderGuiTexts(renderTexts); textRenderer->renderGuiTexts(renderTexts);