Hi everyone,
I'm trying to write some code that can load various fonts and keep them cached in memory. However, for some reason, only the last font loaded properly displays. When I select any of the earlier fonts, all I see is a few dots (looks like 2x2 pixels).
It's probably something super obvious, but I can't seem to figure out what's going wrong here. The relevant code:
TileSet.hpp
struct Font_t {
std::string Family;
std::string Style;
sf::Font FontData;
};
class TileSet{
public:
const sf::Font &Get_Font_By_Name(std::string Name, std::string Style);
protected:
void _LoadFonts(std::shared_ptr<SQLite_TileSet> MYDBC);
std::vector<std::shared_ptr<Font_t>> Loaded_Fonts;
}
TileSet.cpp
void TileSet::_LoadFonts(std::shared_ptr<SQLite_TileSet> MYDBC) {
try {
std::vector<uint32_t> FontIDs = MYDBC->Get_FontIDs();
for (uint32_t FontID : FontIDs) {
try {
std::vector<char> ThisFont = MYDBC->Get_Font_By_ID(FontID);
std::shared_ptr<Font_t> NewFont = std::make_shared<Font_t>();
NewFont->Style = MYDBC->Get_Font_Style_By_ID(FontID);
NewFont->FontData.loadFromMemory(ThisFont.data(), ThisFont.size());
NewFont->Family = NewFont->FontData.getInfo().family;
Loaded_Fonts.push_back(NewFont);
} catch (...) {
}
}
} catch (...) {
}
}
const sf::Font &TileSet::Get_Font_By_Name(std::string Family,
std::string Style) {
for (int i = 0; i < Loaded_Fonts.size(); i++) {
if (Loaded_Fonts[ i ]->Family == Family && Loaded_Fonts[ i ]->Style == Style) {
return Loaded_Fonts[ i ]->FontData;
}
}
}
MainMenu.cpp
sf::Text GameName;
GameName.setFont(My_TileSet->Get_Font_By_Name("OpenDyslexic", "Regular"));
GameName.setString("GameTitle");
GameName.setCharacterSize(18);
GameName.setPosition(Pos_X + 10, Pos_Y + 30);
My_Window->draw(GameName);