Symphony Of Empires
font_sdf.hpp
Go to the documentation of this file.
1 // Eng3D - General purpouse game engine
2 // Copyright (C) 2021, Eng3D contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // font_sdf.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <string>
28 #include <unordered_map>
29 #include <memory>
30 #include <vector>
31 
32 #include <glm/vec3.hpp>
33 
34 #include "eng3d/rectangle.hpp"
35 
36 namespace Eng3D {
37  namespace OpenGL {
38  class Program;
39  }
40  class Texture;
41  class Camera;
42  struct TriangleList;
43 
44  struct Glyph {
45  Glyph() = default;
46  Glyph(float _advance, Eng3D::Rectangle _atlas_bounds, Eng3D::Rectangle _plane_bounds);
47  ~Glyph() = default;
48 
49  float advance;
52  };
53 
54  struct Label3D {
55  Label3D(Eng3D::TriangleList* triangles, float size, glm::vec3 center);
56  ~Label3D() = default;
57  void draw();
58  float size;
59  glm::vec3 center;
60  private:
61  std::unique_ptr<Eng3D::TriangleList> triangles;
62  };
63 
64  struct FontSDF {
65  FontSDF(const std::string& filename);
66  std::unique_ptr<Eng3D::Label3D> gen_text(const std::string& text, glm::vec2 pmin, glm::vec2 pmax, glm::vec2 p0, float width);
67  void draw(const std::vector<std::unique_ptr<Label3D>>& labels, const Eng3D::Camera& camera, bool sphere);
68  private:
69  std::unordered_map<uint32_t, Glyph> unicode_map;
70  std::shared_ptr<Eng3D::Texture> atlas;
71  std::unique_ptr<Eng3D::OpenGL::Program> sphere_shader;
72  std::unique_ptr<Eng3D::OpenGL::Program> flat_shader;
73  };
74 }
void draw(const std::vector< std::unique_ptr< Label3D >> &labels, const Eng3D::Camera &camera, bool sphere)
Definition: font_sdf.cpp:167
FontSDF(const std::string &filename)
Definition: font_sdf.cpp:49
std::unique_ptr< Eng3D::Label3D > gen_text(const std::string &text, glm::vec2 pmin, glm::vec2 pmax, glm::vec2 p0, float width)
Definition: font_sdf.cpp:105
float advance
Definition: font_sdf.hpp:49
~Glyph()=default
Glyph()=default
Eng3D::Rectangle plane_bounds
Definition: font_sdf.hpp:51
Eng3D::Rectangle atlas_bounds
Definition: font_sdf.hpp:50
Label3D(Eng3D::TriangleList *triangles, float size, glm::vec3 center)
Definition: font_sdf.cpp:185
~Label3D()=default
glm::vec3 center
Definition: font_sdf.hpp:59