Sistema de Renderizado de Texto (TTF).

Hemos implementado un sistema para el renderizado de textos mediante fuentes TTF. Para ello utilizamos la librería SDL_TTF.
Se ha creado una clase Wrapper (UE::Font) que gestiona una fuente. Está diseñado para poder tener un cache de fuentes de diferentes tamaños. Es posible que hagamos un refactor al AssetManager para convertir las texturas a un Wrapper (más que nada para limpiar el código del AsMng y llevarme la responsabilidad de las texturas a otro sitio.
This commit is contained in:
2022-02-21 20:17:47 +01:00
parent d19f4593d5
commit 9098f16f81
28 changed files with 1493 additions and 11 deletions
+36 -1
View File
@@ -4,15 +4,18 @@
#include "Scene\Scene.h"
#include "Render\Renderer.h"
#include "Assets\AssetManager.h"
#include "Drawables\Sprite.h"
#include "Logging\Logger.h"
#include "Drawables\Sprite.h"
#include "Drawables\TextBox.h"
#include "Time\Time.h"
#include <iostream>
#include <vector>
#include <SDL.h>
#include <SDL_ttf.h>
#include <ImGui\imgui.h>
@@ -40,6 +43,14 @@ public:
sprites.push_back(sp2);
sprites.push_back(bg);
UE::Font* OP_Regular = as->GetFont("OpenSans_Regular");
//TTF_Font* OP_Bold = as->GetFont("OpenSans_Bold");
UE::TextBox text1(OP_Regular);
//UE::TextBox text2(OP_Bold, "Otro texto");
texts.push_back(text1);
//texts.push_back(text2);
}
void SceneUpdate() override
@@ -73,6 +84,10 @@ public:
renderer->Render(sp);
}
}
for (UE::TextBox& text : texts)
{
renderer->Render(text);
}
ImguiRender();
}
@@ -95,7 +110,10 @@ public:
break;
}
case SDLK_F2:
{
debugGUI = !debugGUI;
break;
}
default:
break;
}
@@ -187,6 +205,20 @@ private:
ImGui::TreePop();
}
ImGui::InputText("Text", textBuffer, 32);
ImGui::SameLine();
if (ImGui::Button("Set text"))
{
texts.at(0).SetText(textBuffer);
}
ImGui::InputInt("Text Size", &textSize);
ImGui::SameLine();
if (ImGui::Button("Set Size"))
{
texts.at(0).SetSize(textSize);
}
ImGui::End();
}
@@ -204,6 +236,7 @@ private:
private:
std::vector<UE::Sprite> sprites;
std::vector<UE::TextBox> texts;
//ImGui:
bool _windowOpen = true;
@@ -215,4 +248,6 @@ private:
bool rendererGUI = false;
bool sceneMngGUI = false;
char textBuffer[32] = {};
int textSize = 12;
};