Skip to content

Commit

Permalink
Add external large atlas font
Browse files Browse the repository at this point in the history
  • Loading branch information
ForserX committed Jan 25, 2025
1 parent 4592352 commit 5bc5953
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions gamedata/configs/engine_external.ltx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ EnableWeaponCollision = false ;Shoker Mod Style

[render]
DisableLoadScreenTips = false
LargeFontAtlas = false

[environment]
ReadSunConfig = false
4 changes: 3 additions & 1 deletion src/xrEngine/EngineExternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ enum class EEngineExternalGame
EnableWeaponCollision
};

enum class EEngineExternalRender {
enum class EEngineExternalRender
{
DisableLoadScreenTips,
LargeFontAtlas,
None
};

Expand Down
15 changes: 14 additions & 1 deletion src/xrEngine/FontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

ENGINE_API CFontManager* g_FontManager = nullptr;

u32 TextureDimension = 2048 * 2;
xr_vector<u32> FontBitmap;

CFontManager::CFontManager()
{
g_FontManager = this;
Expand All @@ -15,16 +18,26 @@ CFontManager::CFontManager()
pFontSystem = nullptr;
pFontSystem16 = nullptr;
pFontStat = nullptr;

if (EngineExternal()[EEngineExternalRender::LargeFontAtlas])
{
TextureDimension *= 2;
}

FontBitmap.resize(TextureDimension * TextureDimension);
}

CFontManager::~CFontManager()
{
Device.seqDeviceReset.Remove(this);

for (auto& fontPair : Fonts) {
for (auto& fontPair : Fonts)
{
xr_delete(fontPair.second);
}
Fonts.clear();

FontBitmap.clear();
}

void CFontManager::InitializeFonts()
Expand Down
8 changes: 4 additions & 4 deletions src/xrEngine/GameFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ xr_vector<xr_string> split(const xr_string& s, char delim)
}
#include <freetype/ftfntfmt.h>

constexpr u32 TextureDimension = 2048 * 2;
static u32 FontBitmap[TextureDimension * TextureDimension] = {};
extern u32 TextureDimension;
extern xr_vector<u32> FontBitmap;

void CGameFont::Initialize2(const char* name, const char* shader, const char* style, u32 size)
{
Expand Down Expand Up @@ -138,7 +138,7 @@ void CGameFont::Initialize2(const char* name, const char* shader, const char* st
}
}
}
ZeroMemory(FontBitmap, sizeof(FontBitmap));
ZeroMemory(FontBitmap.data(), sizeof(u32) * (TextureDimension * TextureDimension));

// есть кучу способов высчитать размер шрифта для скейлинга
// 1. основываясь на DPI(PPI), однако, как не вычисляй его он всегда считается исходя из разрешения моника(системы) и 23 дюймов(мб с дровами на моник - из реальных дюймов)
Expand Down Expand Up @@ -342,7 +342,7 @@ void CGameFont::Initialize2(const char* name, const char* shader, const char* st
#endif
R_ASSERT2(TargetDemensionY <= TextureDimension, "Font too large, or dimension texture is too small");

pFontRender->CreateFontAtlas(TextureDimension, TargetDemensionY, textureName, FontBitmap);
pFontRender->CreateFontAtlas(TextureDimension, TargetDemensionY, textureName, FontBitmap.data());

FS.r_close(FontFile);
pFontRender->Initialize(shader, textureName);
Expand Down

0 comments on commit 5bc5953

Please sign in to comment.