Restructure and reload font
This commit is contained in:
@@ -360,3 +360,29 @@ Int GetLineSpacing(Font *font) {
|
||||
Int result = (Int)(font->ascent - font->descent + font->line_gap);
|
||||
return result;
|
||||
}
|
||||
|
||||
String FontPath = "C:\\Windows\\Fonts\\consola.ttf";
|
||||
void ReloadFont(int32_t size) {
|
||||
size = ClampBottom(2, size);
|
||||
if (MainFont.texture_id) {
|
||||
glDeleteTextures(1, &MainFont.texture_id);
|
||||
Dealloc(&MainFont.glyphs);
|
||||
MainFont = {};
|
||||
}
|
||||
|
||||
Scratch scratch;
|
||||
Atlas atlas = CreateAtlas(scratch, {1024, 1024});
|
||||
MainFont = CreateFont(&atlas, size, FontPath);
|
||||
{
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &atlas.texture_id);
|
||||
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTextureStorage2D(atlas.texture_id, 1, GL_R8, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y);
|
||||
glTextureSubImage2D(atlas.texture_id, 0, 0, 0, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y, GL_RED, GL_UNSIGNED_BYTE, atlas.bitmap);
|
||||
}
|
||||
MainFont.texture_id = atlas.texture_id;
|
||||
FontCharSpacing = GetCharSpacing(&MainFont);
|
||||
FontLineSpacing = GetLineSpacing(&MainFont);
|
||||
}
|
||||
Reference in New Issue
Block a user