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
|
POSX=300
|
||||||
POSY=30
|
POSY=30
|
||||||
FONT=/usr/share/fonts/noto/NotoSans-Bold.ttf
|
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
|
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.
|
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:
|
public:
|
||||||
Font() = delete;
|
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);
|
void RenderText(GLuint VAO, GLuint VBO, GLuint shaderProgram, const char* text, float x, float y, float scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupCharMap(FT_Face& face);
|
void SetupCharMap(FT_Face& face, FT_UInt size);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool LoadError;
|
bool LoadError;
|
||||||
|
@ -8,6 +8,7 @@ struct Config
|
|||||||
uint32_t pos_x = 10;
|
uint32_t pos_x = 10;
|
||||||
uint32_t pos_y = 25;
|
uint32_t pos_y = 25;
|
||||||
std::string font = "/usr/share/fonts/noto/NotoSans-Regular.ttf";
|
std::string font = "/usr/share/fonts/noto/NotoSans-Regular.ttf";
|
||||||
|
uint16_t font_size = 32;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "character_utils.h"
|
#include "character_utils.h"
|
||||||
|
|
||||||
|
|
||||||
Font::Font(const char* font)
|
Font::Font(const char* font, FT_UInt size)
|
||||||
: LoadError(false), m_Characters()
|
: LoadError(false), m_Characters()
|
||||||
{
|
{
|
||||||
FT_Library ft;
|
FT_Library ft;
|
||||||
@ -41,17 +41,17 @@ Font::Font(const char* font)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupCharMap(face);
|
SetupCharMap(face, size);
|
||||||
|
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
FT_Done_FreeType(ft);
|
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
|
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++) {
|
for (unsigned char c = 0; c < 128; c++) {
|
||||||
// load character glyph
|
// load character glyph
|
||||||
|
@ -131,6 +131,8 @@ Config readConfig(std::filesystem::path config_path)
|
|||||||
config.pos_y = std::stoi(value);
|
config.pos_y = std::stoi(value);
|
||||||
} else if (name == "FONT") {
|
} else if (name == "FONT") {
|
||||||
config.font = value;
|
config.font = value;
|
||||||
|
} else if (name == "FONT_SIZE") {
|
||||||
|
config.font_size = std::stoi(value);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Warning: Invalid line in config file" << std::endl;
|
std::cerr << "Warning: Invalid line in config file" << std::endl;
|
||||||
std::cerr << line_num << " | " << line << 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));
|
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) {
|
if (font.LoadError) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user