SuzanneIsland: An island of Real-time rendering effects!
src
textrenderer.h
1
#pragma once
2
3
#include <iostream>
4
#include <string>
5
#include <map>
6
7
#include <GL/glew.h>
8
#include <GLFW/glfw3.h>
9
#include <glm/glm.hpp>
10
#include <glm/gtc/matrix_transform.hpp>
11
#include <glm/gtc/type_ptr.hpp>
12
13
// FreeType
14
#include <ft2build.h>
15
#include FT_FREETYPE_H
16
17
#include "shader.h"
18
19
21
struct
Glyph
{
22
GLuint
textureId
;
23
glm::ivec2
size
;
24
glm::ivec2
bearing
;
25
GLuint
advance
;
26
};
27
28
29
class
TextRenderer
30
{
31
public
:
32
TextRenderer
(
const
std::string &fontPath,
const
GLuint &windowWidth,
const
GLuint &windowHeight);
33
~
TextRenderer
();
34
36
void
renderText(
37
const
std::string &text,
38
GLfloat x,
39
GLfloat y,
40
GLfloat scaleFactor,
41
const
glm::vec3 &color
42
);
43
private
:
44
Shader
*textShader;
45
GLuint vao, vbo;
46
47
// stores preloaded glyphs for each character of 7-bit ASCII
48
std::map<GLchar, Glyph> glyphs;
49
50
// Load FreeType glyphs for each character and create opengl textures
51
// from glyph bitmaps. The resulting Glyph structs (texture and glyph
52
// metrics) are stored in the glyphs map.
53
void
loadGlyphs(
const
std::string &fontPath);
54
};
55
Glyph::textureId
GLuint textureId
opengl texture handle
Definition:
textrenderer.h:22
Shader
Shader class.
Definition:
shader.h:15
Glyph::advance
GLuint advance
horizontal offset from current to next glyph origin (in 1/64th pixels)
Definition:
textrenderer.h:25
TextRenderer
Definition:
textrenderer.h:29
Glyph::bearing
glm::ivec2 bearing
horizontal offset from origin to left of glyph / vertical from baseline to top of glyph (in pixels) ...
Definition:
textrenderer.h:24
Glyph::size
glm::ivec2 size
width/height (in pixels)
Definition:
textrenderer.h:23
Glyph
Holds information defining the glyph (visual representation) of a character.
Definition:
textrenderer.h:21
Generated by
1.8.12