8#include <glm/gtc/type_ptr.hpp>
10#include <nlohmann/json.hpp>
12#include "galaxy/core/ServiceLocator.hpp"
35 this->
m_colour = std::move(t.m_colour);
36 this->
m_vao = std::move(t.m_vao);
37 this->
m_rt = std::move(t.m_rt);
40 this->
m_text = std::move(t.m_text);
51 this->
m_vao = std::move(t.m_vao);
52 this->
m_colour = std::move(t.m_colour);
53 this->
m_rt = std::move(t.m_rt);
56 this->
m_text = std::move(t.m_text);
79 strutils::replace_all(
m_text,
"\t",
" ");
93 auto& fonts = core::ServiceLocator<resource::Fonts>::ref();
97 const auto width = vec.x;
107 std::size_t start = 0;
108 std::size_t end =
m_text.find(
'\n');
110 auto proj = glm::ortho(0.0f,
width,
height, 0.0f, -1.0f, 1.0f);
113 while (end != std::string::npos)
115 const auto block =
m_text.substr(start, end);
123 glm::value_ptr(proj),
124 static_cast<msdfgl_printf_flags
>(MSDFGL_UTF8 | MSDFGL_KERNING),
130 end =
m_text.find(
'\n', start);
133 const auto last_block =
m_text.substr(start, end);
142 glm::value_ptr(proj),
143 static_cast<msdfgl_printf_flags
>(MSDFGL_UTF8 | MSDFGL_KERNING),
161 strutils::replace_all(
m_text,
"\t",
" ");
#define GALAXY_LOG(level, msg,...)
thread_local const float vertices[]
Video.cpp galaxy.
Represents an RGBA colour.
msdfgl_font_t handle()
Get handle to internal font object.
msdfgl_font_t m_font
Font object.
glm::vec2 get_text_size(const std::string &text, const float size)
Query text size with font.
float vertical_advance(const float size) const
Get vertical advance for drawing multiline text.
Draw to an opengl texture instead of the screen.
int height() const
Get texture height.
void unbind()
Deactivate context.
void create(const int width, const int height)
Create framebuffer and texture.
void recreate(const int width=-1, const int height=-1)
Destroy and re-create framebuffer.
void bind(bool clear=true)
Activate context.
int width() const
Get texture width.
String of glyphs rendered with a font.
const std::string & get_font() const
Get font ID.
const std::string & get_text() const
Get text.
Alignment get_alignment() const
Get the text alignment.
void create(std::string_view text, const float size, const std::string &font, const graphics::Colour &colour, Alignment alignment=Alignment::LEFT)
Creates the rendered text.
Text & operator=(Text &&)
Move assignment operator.
std::string m_font_name
Font Name.
void set_font(std::string_view font)
Update the font used.
graphics::Colour m_colour
Text colour.
graphics::RenderTexture & render_texture()
Get render texture.
graphics::Font * m_font
Pointer to font resource.
float height() const
Get text height.
graphics::VertexArray m_vao
Vertex Array Object.
Alignment m_alignment
Alignment.
void update()
Update the rendered text.
float get_size() const
Get text em size.
float width() const
Get text width.
graphics::VertexArray & vao()
Get vertex array.
graphics::RenderTexture m_rt
Font render texture.
Abstraction for OpenGL vertex array objects.
void buffer(std::span< Vertex > vertices, std::span< unsigned int > indicies)
Create vertex array object.
void sub_buffer(const unsigned int index, std::span< Vertex > vertices)
Sub-buffer vertex array.
std::array< Vertex, 4 > gen_quad_vertices(const float width, const float height)
Generate some default verticies.
std::array< unsigned int, 6 > gen_default_indices()
Generate some default indicies.