Textogl  1.1.2
OpenGL Text renderer
font.hpp
Go to the documentation of this file.
1 
4 // Copyright 2022 Matthew Chandler
5 
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 
24 #ifndef FONT_HPP
25 #define FONT_HPP
26 
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 #include "types.hpp"
32 
34 namespace textogl
35 {
37  enum Text_origin: int
38  {
43 
45  ORIGIN_VERT_TOP = 0x04,
47  ORIGIN_VERT_CENTER = 0x0C
48  };
49 
51 
59  class Font_sys
60  {
61  public:
63  Font_sys(const std::string & font_path,
64  const unsigned int font_size
65  );
67 
69  Font_sys(const unsigned char * font_data,
70  const std::size_t font_data_size,
71  const unsigned int font_size
72  );
73 
75 
79  void resize(const unsigned int font_size
80  );
81 
83 
88  void render_text(const std::string & utf8_input,
89  const Color & color,
90  const Vec2<float> & win_size,
91  const Vec2<float> & pos,
92  const int align_flags = 0
93  );
94 
96 
101  void render_text_rotate(const std::string & utf8_input,
102  const Color & color,
103  const Vec2<float> & win_size,
104  const Vec2<float> & pos,
105  const float rotation,
106  const int align_flags = 0
107  );
108 
110 
115  void render_text_mat(const std::string & utf8_input,
116  const Color & color,
120  const Mat4<float> & model_view_projection
121  );
122 
123  private:
124  struct Impl;
125  std::shared_ptr<Impl> pimpl;
126 
128  friend class Static_text;
130  };
131 }
132 
133 #endif // FONT_HPP
Container for font and text rendering.
Definition: font.hpp:60
void resize(const unsigned int font_size)
Resize font.
void render_text(const std::string &utf8_input, const Color &color, const Vec2< float > &win_size, const Vec2< float > &pos, const int align_flags=0)
Render given text.
Font_sys(const std::string &font_path, const unsigned int font_size)
Load a font file at a specified size.
Font_sys(const unsigned char *font_data, const std::size_t font_data_size, const unsigned int font_size)
Load a font at a specified size from memory.
void render_text_mat(const std::string &utf8_input, const Color &color, const Mat4< float > &model_view_projection)
Render given text, using a model view projection matrix.
void render_text_rotate(const std::string &utf8_input, const Color &color, const Vec2< float > &win_size, const Vec2< float > &pos, const float rotation, const int align_flags=0)
Render given text, with rotatation.
Object for text which does not change often.
Definition: static_text.hpp:43
OpenGL Font rendering types.
Definition: font.hpp:35
Vec4< float > Color
Color vector
Definition: types.hpp:191
typename detail::Mat4_t< T >::type Mat4
4D Matrix
Definition: types.hpp:186
Text_origin
Text origin specification.
Definition: font.hpp:38
@ ORIGIN_VERT_CENTER
Vertical text origin at center.
Definition: font.hpp:47
@ ORIGIN_HORIZ_BASELINE
Horizontal text origin at baseline.
Definition: font.hpp:39
@ ORIGIN_HORIZ_CENTER
Horizontal text origin at center.
Definition: font.hpp:42
@ ORIGIN_VERT_TOP
Vertical text origin at left edge.
Definition: font.hpp:45
@ ORIGIN_VERT_BOTTOM
Vertical text origin at right edge.
Definition: font.hpp:46
@ ORIGIN_HORIZ_RIGHT
Horizontal text origin at right edge.
Definition: font.hpp:41
@ ORIGIN_VERT_BASELINE
Vertical text origin at baseline.
Definition: font.hpp:44
@ ORIGIN_HORIZ_LEFT
Horizontal text origin at left edge.
Definition: font.hpp:40
typename detail::Vec2_t< T >::type Vec2
2D Vector
Definition: types.hpp:176
Vector and matrix types.