Implement rounding on DrawString input coordinates (Crisp text rendering even when users pass in non-integer values, however, still need to account for non-integer scaling).

This commit is contained in:
2024-10-11 13:29:53 -04:00
parent 881d031f3c
commit 5b19d26b79
2 changed files with 20 additions and 1 deletions

View File

@@ -1,4 +1,3 @@
#include <JGL/JGL.h>
#include <rewindow/types/window.h>
#include <Colors.hpp>

View File

@@ -95,6 +95,15 @@ namespace JGL {
// Offset by height to render at "correct" location.
y += size;
bool round_text_coords_for_crisp_rendering = true;
// TODO: This currently does not account for non-integer scale factors.
if (round_text_coords_for_crisp_rendering)
{
x = J3ML::Math::Floor(x);
y = J3ML::Math::Floor(y);
}
CachedFont* cachedFont = fontCache.getFont(size, font.index);
if (font.face == nullptr)
@@ -153,6 +162,17 @@ namespace JGL {
float y = pos.y;
float z = pos.z;
bool round_text_coords_for_crisp_rendering = true;
// TODO: This currently does not account for non-integer scale factors.
if (round_text_coords_for_crisp_rendering)
{
x = J3ML::Math::Floor(x);
y = J3ML::Math::Floor(y);
z = J3ML::Math::Floor(z);
}
CachedFont* cachedFont = fontCache.getFont(size, font.index);
if (font.face == nullptr)
jlog::Fatal("Drawing a string with an uninitialized font?");