From a1ca7ace7792fb8efc36757a3916bdc33b5488e3 Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 17 Apr 2025 13:57:03 -0400 Subject: [PATCH] Flip order of J2D::DrawString argument, so that we can default scale to 1, and add vector2 overload. --- assets/shader_programs/test_vertex.glsl | 2 ++ include/JGL/JGL.h | 3 ++- src/renderer/OpenGL/J2D.cpp | 5 +++++ src/renderer/OpenGL/TextRendering.cpp | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/shader_programs/test_vertex.glsl b/assets/shader_programs/test_vertex.glsl index a243a19..640d743 100644 --- a/assets/shader_programs/test_vertex.glsl +++ b/assets/shader_programs/test_vertex.glsl @@ -1,5 +1,7 @@ #version 120 +#include "shared.glsl" + void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } diff --git a/include/JGL/JGL.h b/include/JGL/JGL.h index 2c5918c..ac60d9e 100644 --- a/include/JGL/JGL.h +++ b/include/JGL/JGL.h @@ -367,8 +367,9 @@ namespace JGL::J2D { /// @param scale The value (in both axes) to scale the text by. Defaults to {1,1}. /// @param size The point-size at which to render the font out. Re-using the same point-size allows efficient glyph caching. /// @param font The font to use for rendering. @see Font. - void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font = Fonts::Jupiteroid); + void DrawString(const Color4& color, const std::string& text, float x, float y, u32 size, float scale = 1.f, const Font& font = Fonts::Jupiteroid); + void DrawString(const Color4& color, const std::string& text, const Vector2& pos, u32 size, float scale = 1.f, const Font& font = Fonts::Jupiteroid); /// Draws an Arc (section of a circle) to the screen. /// @param color A 3-or-4 channel color value. @see class Color3, class Color4 diff --git a/src/renderer/OpenGL/J2D.cpp b/src/renderer/OpenGL/J2D.cpp index b44d532..a963041 100644 --- a/src/renderer/OpenGL/J2D.cpp +++ b/src/renderer/OpenGL/J2D.cpp @@ -1083,3 +1083,8 @@ void J2D::DrawSprite(const TextureAtlas* texture_atlas, const AtlasRegion& atlas void J2D::DrawSprite(const TextureAtlas& texture_atlas, const AtlasRegion& atlas_region, const Vector2& position, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) { J2D::DrawSprite(&texture_atlas, atlas_region, position, rad_rotation, origin, scale, color); } + +void J2D::DrawString(const Color4 &color, const std::string &text, const Vector2 &pos, u32 size, float scale, + const Font &font) { + DrawString(color, text, pos.x, pos.y, size, scale, font); +} diff --git a/src/renderer/OpenGL/TextRendering.cpp b/src/renderer/OpenGL/TextRendering.cpp index 4db8b27..4e9585c 100644 --- a/src/renderer/OpenGL/TextRendering.cpp +++ b/src/renderer/OpenGL/TextRendering.cpp @@ -95,7 +95,7 @@ namespace JGL { return cachedFont; } - void J2D::DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font) { + void J2D::DrawString(const Color4& color, const std::string& text, float x, float y, u32 size, float scale, const Font& font) { // Offset by height to render at "correct" location. y += size; -- 2.39.5