jGL
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1#ifndef FONT_H
2#define FONT_H
3
4#include <jGL/glyph.h>
5#include <jGL/texture.h>
6
7#include <map>
8#include <algorithm>
9
10
11namespace jGL
12{
13 class Font
14 {
15
16 public:
17
18 Font(uint8_t w);
19
20 virtual ~Font() {}
21
22 const glm::ivec2 getBitmapSize() const { return glm::ivec2(fontBitmap->size().x, fontBitmap->size().y); }
23
24 std::array<glm::vec4, 6> getGlyphVertices(float x, float y, float scale, unsigned char c);
25 glm::vec4 getGlyphOffset(unsigned char c) { return glyphOffset[c]; }
26 glm::ivec2 getGlyphSize(unsigned char c) { return glyphs[c].getSize(); }
27
28 float spacing(float scale) { return scale * width; }
29
30 void bind(unsigned int b) { fontBitmap->bind(b); }
31
32 protected:
33
34 uint8_t width;
35
36 std::map<unsigned char, Glyph> glyphs;
37 std::map<unsigned char, glm::vec4> glyphOffset;
38
39 std::shared_ptr<Texture> fontBitmap;
40 std::vector<std::byte> bitmapPixels;
41 uint16_t bw, bh;
42
43 };
44}
45
46#endif /* FONT_H */
Definition font.h:14
uint8_t width
Definition font.h:34
uint16_t bh
Definition font.h:41
const glm::ivec2 getBitmapSize() const
Definition font.h:22
glm::ivec2 getGlyphSize(unsigned char c)
Definition font.h:26
std::array< glm::vec4, 6 > getGlyphVertices(float x, float y, float scale, unsigned char c)
Definition font.cpp:104
float spacing(float scale)
Definition font.h:28
virtual ~Font()
Definition font.h:20
uint16_t bw
Definition font.h:41
std::map< unsigned char, glm::vec4 > glyphOffset
Definition font.h:37
glm::vec4 getGlyphOffset(unsigned char c)
Definition font.h:25
std::shared_ptr< Texture > fontBitmap
Definition font.h:39
std::map< unsigned char, Glyph > glyphs
Definition font.h:36
void bind(unsigned int b)
Definition font.h:30
std::vector< std::byte > bitmapPixels
Definition font.h:40
A drawable graphic.
Definition id.h:10