Untitled Game engine no.5  1.0
Font.hpp
1 //
2 // Created by jibbo on 3/12/21.
3 //
4 
5 #ifndef ENGINE_PROJ_GLYPH_H
6 #define ENGINE_PROJ_GLYPH_H
7 
8 #include "pch.hpp"
9 #include "Components.hpp"
10 #include "MeshRenderer.hpp"
11 #include "Texture.hpp"
12 #include "GLTexture.hpp"
13 #include "ft2build.h"
14 #include FT_FREETYPE_H
15 #include "Shader.hpp"
16 
17 namespace Engine {
23  struct Glyph : TextureLookup {
25  Glyph(const Ref<Texture>& texture, const Ref<TextureMap>& map,
26  uint cwidth, uint cheight, int32_t leftShift, int32_t topShift, uint32_t adv):
27  TextureLookup(texture, map, cwidth, cheight), left(leftShift), top(topShift), advance(adv) {};
29  int left;
31  int top;
33  uint32_t advance;
34  };
35 
36  //TODO: implement and test
37 // struct Text {
38 // /// Font storage
39 // Ref<Font> font;
40 // /// text to render
41 // std::string text = "";
42 // /// rendering alignment origin
43 // TextAlignment alignment = CENTER;
44 // /// Mesh rendering link
45 // Ref<MeshRenderer> renderer;
46 //
47 // /// generate a Texture Mesh, requires font data and a string
48 // void SetText(const std::string &tData, const Ref<Font> &fData = nullptr) {
49 // font = fData == nullptr ? font : fData;
50 // if (font == nullptr) {
51 // std::cerr << "font data cannot be null." << std::endl;
52 // return;
53 // }
54 // }
55 // };
56 
57 
63  struct Font {
64  public:
66  static uint GLYPH_COUNT;
68  static FT_Library FT;
70  static void InitFont();
72  static void FinalizeFonts();
74  explicit Font(const char * path);
75 
77  std::vector<Ref<Glyph>> glyphs;
79  bool singleTex = true;
80 
89  void renderText(const std::string &text,
90  Ref<MeshRenderer> &meshRenderer,
91  Allignment alignment = CENTER,
92  float z = 0);
93 
94  void renderText(const std::string &text, MeshRenderer* meshRenderer, Allignment alignment = CENTER, float z = 0);
95 
96  };
97 }
98 
99 #endif //ENGINE_PROJ_GLYPH_H
Engine::MeshRenderer
Scene Component for passing drawing data to the renderer. Stores vertex data and references to the te...
Definition: MeshRenderer.hpp:15
Engine::Font::GLYPH_COUNT
static uint GLYPH_COUNT
Number of required glyphs.
Definition: Font.hpp:66
Engine::Font
Data structure for storing font texture data. Doubles as a library for loading fonts into memory.
Definition: Font.hpp:63
Engine::TextureLookup::map
Ref< TextureMap > map
Mapping reference.
Definition: Texture.hpp:97
Engine::Font::FT
static FT_Library FT
link to the Freetype font library
Definition: Font.hpp:68
Engine::Glyph::Glyph
Glyph(const Ref< Texture > &texture, const Ref< TextureMap > &map, uint cwidth, uint cheight, int32_t leftShift, int32_t topShift, uint32_t adv)
create a glyph from a texture and character data
Definition: Font.hpp:25
Engine::Ref
std::shared_ptr< T > Ref
Has stuff for making references a lot more easily shared smart pointer.
Definition: Base.hpp:21
Engine::Font::renderText
void renderText(const std::string &text, Ref< MeshRenderer > &meshRenderer, Allignment alignment=CENTER, float z=0)
Renders texture data from a string and applies it to a MeshRenderer.
Definition: Font.cpp:86
Engine::TextureLookup
Wrapper for a texture reference and a texture mapping.
Definition: Texture.hpp:92
Engine::Font::FinalizeFonts
static void FinalizeFonts()
Delete any font loader data, not font texture data.
Definition: Font.cpp:28
Engine::Allignment
Allignment
enumeration representing alignment of text in a string of text.
Definition: Components.hpp:358
Engine::Glyph
Definition: Font.hpp:23
Engine::Font::glyphs
std::vector< Ref< Glyph > > glyphs
lookup table from a ascii character code to graphical data
Definition: Font.hpp:77
Engine::Glyph::top
int top
distance from the texture to the top of the line
Definition: Font.hpp:31
Engine::Font::Font
Font(const char *path)
Load a font object from a system path.
Definition: Font.cpp:32
Engine::Font::InitFont
static void InitFont()
Initialize global font data.
Definition: Font.cpp:24
Engine
Definition: Animation.hpp:14
Engine::Glyph::advance
uint32_t advance
total size of the character from the edge of the last character to beginning of the next character
Definition: Font.hpp:33
Engine::Glyph::left
int left
distance from the texture to the end of the last character
Definition: Font.hpp:27
Engine::Font::singleTex
bool singleTex
is there one texture for all of the characters?
Definition: Font.hpp:79