Skip to content

Commit 5e22c2e

Browse files
Raelrjonjondev
authored andcommitted
Removed default font from TextRenderer
1 parent f74fbb2 commit 5e22c2e

File tree

8 files changed

+36
-29
lines changed

8 files changed

+36
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $ sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi
8989
```
9090
```console
9191
// Windows
92-
> ./scripts/setup.bat
92+
> ./scripts/Setup.ps1
9393
```
9494

9595
3. This should install all required dependencies. Once completed a `.env` file will be generated with all required variables. If the build is completed with no issue then you can proceed to build the project.
@@ -104,14 +104,14 @@ $ ./scripts/setup.sh --include-validation-layers
104104
```
105105
```console
106106
// Windows
107-
> ./scripts/setup.bat --include-validation-layers
107+
> ./scripts/Setup.ps1 -Include_Validation_Layers
108108
```
109109

110110
**NOTE**: Building with this option can take some time to complete. Please be patient while the project builds the required validation layers.
111111

112112
### Building the Project
113113

114-
Assuming all dependencies have been satisfied, the project can be build using the following command:
114+
Assuming all dependencies have been satisfied, the project can be built using the following command:
115115

116116
```console
117117
// Linux and macOS

engine/render/renderer/Renderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Renderer* Renderer::instance {nullptr};
2020
Vulkan::CommandBuffer Renderer::commandBuffers;
2121
uint32_t Renderer::currentFrameIndex = 0;
2222

23-
Renderer::Renderer(Window& window, const char* defaultFontPath) : window {window}
23+
Renderer::Renderer(Window& window) : window {window}
2424
{
2525
Statics::Initialise();
2626

@@ -40,7 +40,7 @@ Renderer::Renderer(Window& window, const char* defaultFontPath) : window {window
4040

4141
DescriptorPool::BuildPool();
4242

43-
Renderer3D::Initialise(defaultFontPath);
43+
Renderer3D::Initialise();
4444
Renderer2D::Initialise();
4545

4646
commandBuffers = Vulkan::CommandBuffer(Vulkan::Swapchain::MAX_FRAMES_IN_FLIGHT);

engine/render/renderer/Renderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Renderer
2626
{
2727
public:
2828

29-
explicit Renderer(Window& window, const char* defaultFontPath);
29+
explicit Renderer(Window& window);
3030

3131
~Renderer();
3232

engine/render/renderer/renderer/Renderer3D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ TextRenderer Renderer3D::textRenderer;
2323

2424
Renderer3D::GlobalData Renderer3D::global3DData;
2525

26-
void Renderer3D::Initialise(const char* defaultTextPath)
26+
void Renderer3D::Initialise()
2727
{
2828
globalDataId = INTERN_STR("globalData");
2929

3030
modelRenderer.Initialise("globalData");
3131
debugRenderer.Initialise("globalData");
3232
billboardRenderer.Initialise("globalData");
3333
lightRenderer.Initialise("globalData");
34-
textRenderer.Initialise(defaultTextPath, "globalData");
34+
textRenderer.Initialise("globalData");
3535

3636
gridMaterial = Vulkan::Material(
3737
Vulkan::Shader::Builder()

engine/render/renderer/renderer/Renderer3D.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Renderer3D
3333
PointLight::Data lightData;
3434
};
3535

36-
static void Initialise(const char* defaulTextPath);
36+
static void Initialise();
3737

3838
static void DrawModel(Model* model,
3939
const Vec3& position,
@@ -58,7 +58,7 @@ class Renderer3D
5858
const Vec3 rotation,
5959
const Vec2 scale,
6060
const IColour& colour,
61-
Vulkan::Font* font = nullptr);
61+
Vulkan::Font* font);
6262

6363
static void RecreateMaterials();
6464

engine/render/renderer/renderer/TextRenderer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
namespace Siege
1616
{
1717

18-
void TextRenderer::Initialise(const char* defaultTextPath, const String& globalDataAttributeName)
18+
void TextRenderer::Initialise(const String& globalDataAttributeName)
1919
{
2020
using Vulkan::Material;
2121
using Vulkan::Mesh;
2222
using Vulkan::Shader;
2323

2424
globalDataId = INTERN_STR(globalDataAttributeName);
2525

26-
defaultFont = Vulkan::Font(defaultTextPath);
26+
defaultTexture = Vulkan::Texture2D("default");
2727

2828
defaultMaterial =
2929
Material(Shader::Builder()
@@ -40,7 +40,7 @@ void TextRenderer::Initialise(const char* defaultTextPath, const String& globalD
4040
Shader::Builder()
4141
.FromFragmentShader("assets/shaders/text2D.frag.spv")
4242
.WithTexture("texture", 0, 16)
43-
.WithDefaultTexture(defaultFont.GetTexture())
43+
.WithDefaultTexture(&defaultTexture)
4444
.Build());
4545

4646
textureId = INTERN_STR("texture");
@@ -61,7 +61,7 @@ void TextRenderer::Initialise(const char* defaultTextPath, const String& globalD
6161

6262
void TextRenderer::Free()
6363
{
64-
defaultFont.Free();
64+
defaultTexture.Free();
6565
defaultMaterial.Free();
6666
for (auto it = perFrameVertexBuffers.CreateIterator(); it; ++it) it->Free();
6767
indexBuffer.Free();
@@ -74,9 +74,9 @@ void TextRenderer::DrawFont(const char* text,
7474
const IColour& colour,
7575
Vulkan::Font* font)
7676
{
77-
auto targetFont = font == nullptr ? &defaultFont : font;
77+
if (font == nullptr) return;
7878

79-
auto texIndex = defaultMaterial.SetTexture(textureId, targetFont->GetTexture());
79+
auto texIndex = defaultMaterial.SetTexture(textureId, font->GetTexture());
8080

8181
if (texIndex >= characters.Count()) characters.Append(MHArray<QuadData>(OFFSET_PER_FONT));
8282

@@ -85,14 +85,14 @@ void TextRenderer::DrawFont(const char* text,
8585
size_t textSize = strlen(text);
8686
float textScale = 64.f;
8787

88-
float totalWidth = (GetTotalTextWidth(text, textSize, targetFont->GetGlyphs()));
88+
float totalWidth = (GetTotalTextWidth(text, textSize, font->GetGlyphs()));
8989

9090
float x = 0 - (totalWidth / 2.f);
9191
float y = 0;
9292

9393
for (size_t i = 0; i < textSize; i++)
9494
{
95-
auto glyph = targetFont->GetGlyph(text[i]);
95+
auto glyph = font->GetGlyph(text[i]);
9696

9797
float height = glyph.height;
9898

engine/render/renderer/renderer/TextRenderer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class TextRenderer
2323
{
2424
public:
2525

26-
void Initialise(const char* defaultTextPath, const String& globalDataAttributeName);
26+
void Initialise(const String& globalDataAttributeName);
2727
void Free();
2828

2929
void DrawFont(const char* text,
3030
const Vec3& position,
3131
const Vec3& rotation,
3232
const Vec2 scale,
3333
const IColour& colour,
34-
Vulkan::Font* font = nullptr);
34+
Vulkan::Font* font);
3535

3636
void RecreateMaterials();
3737

@@ -67,11 +67,11 @@ class TextRenderer
6767
Hash::StringId textureId;
6868

6969
MSArray<MHArray<QuadData>, MAX_FONTS> characters;
70-
7170
MHArray<Vulkan::VertexBuffer> perFrameVertexBuffers;
71+
7272
Vulkan::IndexBuffer indexBuffer;
7373

74-
Vulkan::Font defaultFont;
74+
Vulkan::Texture2D defaultTexture;
7575
Vulkan::Material defaultMaterial;
7676
};
7777

examples/render/src/main.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main()
4646

4747
Siege::Input::SetWindowPointer(&window);
4848

49-
Siege::Renderer renderer(window, "assets/fonts/PublicPixel.ttf");
49+
Siege::Renderer renderer(window);
5050

5151
Camera camera;
5252

@@ -55,6 +55,7 @@ int main()
5555
auto cappy = Siege::Vulkan::Texture2D("Cthulhu", "assets/textures/cappy.png");
5656

5757
auto meslo = Siege::Vulkan::Font("assets/fonts/meslo-lg/MesloLGS-Regular.ttf");
58+
auto pixel = Siege::Vulkan::Font("assets/fonts/PublicPixel.ttf");
5859

5960
// Shader Declaration
6061

@@ -198,7 +199,8 @@ int main()
198199
{0.f, -.85f, -.51f},
199200
{},
200201
{.13f, .13f},
201-
Siege::IColour::White);
202+
Siege::IColour::White,
203+
&pixel);
202204
Siege::Renderer3D::DrawText3D("AryehThulu",
203205
{-1.95f, -.75f, 2.95f},
204206
{},
@@ -209,12 +211,14 @@ int main()
209211
{2.f, -.75f, 2.95f},
210212
{},
211213
{.25f, .25f},
212-
Siege::IColour::Blue);
214+
Siege::IColour::Blue,
215+
&pixel);
213216
Siege::Renderer3D::DrawText3D("Default Texture",
214217
{0.f, -.8f, 2.95f},
215218
{},
216219
{.1f, .1f},
217-
Siege::IColour::Red);
220+
Siege::IColour::Red,
221+
&pixel);
218222

219223
Siege::Renderer3D::DrawText3D("Wow, isn't it great that we can finally render text?",
220224
{2.99f, -3.f, 0.f},
@@ -226,7 +230,8 @@ int main()
226230
{2.99f, -2.4f, 0.f},
227231
{0.f, 1.5707963268f, 0.1f},
228232
{.25f, .25f},
229-
Siege::IColour::Red);
233+
Siege::IColour::Red,
234+
&pixel);
230235
Siege::Renderer3D::DrawText3D("Yeah but it was like... hard",
231236
{2.99f, -2.f, 0.f},
232237
{0.f, 1.5707963268f, 0.f},
@@ -249,13 +254,15 @@ int main()
249254
{2.99f, -1.2f, -1.7f},
250255
{0.f, 1.5707963268f, -0.1f},
251256
{.25f, .25f},
252-
Siege::IColour::Blue);
257+
Siege::IColour::Blue,
258+
&pixel);
253259

254260
Siege::Renderer3D::DrawText3D("But hey, at least it's done, right?",
255261
{2.99f, -.5f, 0.f},
256262
{0.f, 1.5707963268f, -0.1f},
257263
{.25f, .25f},
258-
Siege::IColour::White);
264+
Siege::IColour::White,
265+
&pixel);
259266

260267
renderer.EndFrame();
261268
}

0 commit comments

Comments
 (0)