27#ifndef EASY3D_RENDERER_TEXT_RENDERER_H
28#define EASY3D_RENDERER_TEXT_RENDERER_H
33#include <easy3d/core/types.h>
60 explicit TextRenderer(
float dpi_scale = 1.0f,
int texture_size = 512,
bool mipmaps =
false);
71 bool add_font(
const std::string &font_file);
76 std::size_t
num_fonts()
const {
return font_ids_.size(); }
81 const std::vector<std::string> &
font_names()
const {
return font_names_; }
99 float draw(
const std::string &text,
float x,
float y,
float font_size,
int font_id = 0,
100 const vec3 &font_color =
vec3(0, 0, 0),
bool upper_left =
true
109 ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER
129 Rect draw(
const std::string &text,
float x,
float y,
float font_size,
Align align = ALIGN_LEFT,
130 int font_id = 0,
const vec3 &font_color =
vec3(0, 0, 0),
131 float line_spacing = 0.0f,
bool upper_left =
true)
const;
172 float string_width(
const std::string& str,
float font_size)
const;
179 float string_height(
const std::string& str,
float font_size)
const;
192 void flush_draw(
const vec3 &font_color)
const;
195 Rect _get_bbox(
const std::string &text,
float size,
float x,
float y,
Align align,
float line_spacing)
const;
200 std::vector<int> font_ids_;
201 std::vector<std::string> font_names_;
The GenericRect class defines a rectangle in the 2D space.
Definition: rect.h:42
TextRenderer enables quick and easy string rendering in OpenGL applications.
Definition: text_renderer.h:53
float string_height(const std::string &str, float font_size) const
Definition: text_renderer.cpp:806
float draw(const std::string &text, float x, float y, float font_size, int font_id=0, const vec3 &font_color=vec3(0, 0, 0), bool upper_left=true) const
Definition: text_renderer.cpp:818
bool kerning() const
Definition: text_renderer.cpp:781
~TextRenderer()
Definition: text_renderer.cpp:736
bool add_font(const std::string &font_file)
Definition: text_renderer.cpp:741
void set_kerning(bool kerning)
Definition: text_renderer.cpp:775
Rect string_bounding_rect(const std::string &str, float x, float y, float font_size) const
Definition: text_renderer.cpp:812
void set_character_spacing(float spacing)
Definition: text_renderer.cpp:761
float string_width(const std::string &str, float font_size) const
Definition: text_renderer.cpp:800
Align
Horizontal alignment.
Definition: text_renderer.h:108
float character_spacing() const
Definition: text_renderer.cpp:767
const std::vector< std::string > & font_names() const
Definition: text_renderer.h:81
TextRenderer(float dpi_scale=1.0f, int texture_size=512, bool mipmaps=false)
Definition: text_renderer.cpp:723
float font_height(float font_size) const
Definition: text_renderer.cpp:789
std::size_t num_fonts() const
Definition: text_renderer.h:76
Definition: collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45