Add configurable font size
This commit is contained in:
parent
198cca5344
commit
9e1089819d
@ -49,6 +49,7 @@ You can configure the position the window requests and the font that is used usi
|
||||
POSX=300
|
||||
POSY=30
|
||||
FONT=/usr/share/fonts/noto/NotoSans-Bold.ttf
|
||||
FONT_SIZE=48
|
||||
```
|
||||
However, when running under Wayland, the requested position of the window will not be respected, so to set the position, as well
|
||||
as removing window decorations, and preventing the window from stealing focus when it is opened, you will need to set window rules.
|
||||
|
@ -16,11 +16,11 @@ class Font
|
||||
{
|
||||
public:
|
||||
Font() = delete;
|
||||
Font(const char* font);
|
||||
Font(const char* font, FT_UInt size);
|
||||
void RenderText(GLuint VAO, GLuint VBO, GLuint shaderProgram, const char* text, float x, float y, float scale);
|
||||
|
||||
private:
|
||||
void SetupCharMap(FT_Face& face);
|
||||
void SetupCharMap(FT_Face& face, FT_UInt size);
|
||||
|
||||
public:
|
||||
bool LoadError;
|
||||
|
@ -8,6 +8,7 @@ struct Config
|
||||
uint32_t pos_x = 10;
|
||||
uint32_t pos_y = 25;
|
||||
std::string font = "/usr/share/fonts/noto/NotoSans-Regular.ttf";
|
||||
uint16_t font_size = 32;
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "character_utils.h"
|
||||
|
||||
|
||||
Font::Font(const char* font)
|
||||
Font::Font(const char* font, FT_UInt size)
|
||||
: LoadError(false), m_Characters()
|
||||
{
|
||||
FT_Library ft;
|
||||
@ -41,17 +41,17 @@ Font::Font(const char* font)
|
||||
return;
|
||||
}
|
||||
|
||||
SetupCharMap(face);
|
||||
SetupCharMap(face, size);
|
||||
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
}
|
||||
|
||||
void Font::SetupCharMap(FT_Face &face)
|
||||
void Font::SetupCharMap(FT_Face &face, FT_UInt size)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // disable byte-alignment restriction
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
|
||||
for (unsigned char c = 0; c < 128; c++) {
|
||||
// load character glyph
|
||||
|
@ -131,6 +131,8 @@ Config readConfig(std::filesystem::path config_path)
|
||||
config.pos_y = std::stoi(value);
|
||||
} else if (name == "FONT") {
|
||||
config.font = value;
|
||||
} else if (name == "FONT_SIZE") {
|
||||
config.font_size = std::stoi(value);
|
||||
} else {
|
||||
std::cerr << "Warning: Invalid line in config file" << std::endl;
|
||||
std::cerr << line_num << " | " << line << std::endl;
|
||||
|
@ -90,7 +90,7 @@ int main()
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||
|
||||
|
||||
Font font(cfg.font.c_str());
|
||||
Font font(cfg.font.c_str(), cfg.font_size);
|
||||
if (font.LoadError) {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user