-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_renderer.hpp
More file actions
44 lines (34 loc) · 1.54 KB
/
text_renderer.hpp
File metadata and controls
44 lines (34 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef TEXT_RENDERER_HPP
#define TEXT_RENDERER_HPP
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <string>
#include <map>
#include "sbpt_generated_includes.hpp"
/// Holds all state information relevant to a character as loaded using FreeType
struct CharacterDrawingData {
unsigned int TextureID; // ID handle of the glyph texture
glm::ivec2 Size; // (WIDTH, HEIGHT)
glm::ivec2 Bearing; // (BEARING_X, BEARING_Y)
unsigned int Advance; // ADVANCE
};
/**
* configure_opengl_for_text_rendering must be called before any other function is called!
* \todo make this not the case, do it automatically.
*/
using GLCharToDrawingData = std::map<GLchar, CharacterDrawingData>;
class TextRenderer {
public:
TextRenderer(const std::string &font_path, unsigned int font_height_px, unsigned int &window_width_px,
unsigned int &window_height_px, ShaderCache &shader_cache);
GLCharToDrawingData generate_font_data(const std::string &font_path, unsigned int font_height_px);
void render_text(const std::string &text, glm::vec2 ndc_coord, float scale, const glm::vec3 &color);
glm::vec2 get_text_dimensions_in_ndc(const std::string &text, float scale) const;
unsigned int num_vertices_per_quad = 6;
unsigned int &window_width_px, &window_height_px;
GLCharToDrawingData gl_char_to_drawing_data;
ShaderCache &shader_cache;
GLuint vertex_attribute_object, vertex_position_buffer_object, texture_coordinate_buffer_object;
};
#endif // TEXT_RENDERER_HPP