Hey, all my images and data files load from a stream fine. apart from fonts, though they are being done in the same way.
I'm using the physfs class from the wiki.
this loads my font
const sf::Font * imageManager::getFont( const sf::String& filename )
{
if(filename.GetSize() < 1)
{
return &sf::Font::GetDefaultFont();
}
// Check, whether the image already exists
std::map<sf::String, sf::Font>::iterator it = fontResources.find(filename);
if(it != fontResources.end())
{
return &it->second;
}
CGameEngine &Game = CGameEngine::getInstance();
sf::String fontpath("fonts/");
fontpath += filename;
std::string s(fontpath);
if(PHYSFS_exists(fontpath.ToAnsiString().c_str()))
{
sf::Font font;
sf::physfs fontstream(fontpath.ToAnsiString().c_str());
// Search project's main directory
if( font.LoadFromStream(fontstream) )
{
fontResources[filename] = font;
//std::cout << "DEBUG_MESSAGE: " << filename << " loading image.\n";
return &fontResources[filename];
}
}
Game.consolePrint("Failed loading font \"" + fontpath + "\"");
return &sf::Font::GetDefaultFont();
}
this fails
if( font.LoadFromStream(fontstream) )
fontstream returns TRUE and not NULL.
if(PHYSFS_exists(fontpath.ToAnsiString().c_str()))
returns true, it exists.
The images, textures is exactly the same, BUT it loads
if(texture.LoadFromStream(imagestream) )
{
This is what loads the file:
sf::physfs::physfs(const char *filename){
file = PHYSFS_openRead(filename);
error = false;
if (file == NULL){
sf::Err() << PHYSFS_getLastError() << std::endl;
error = true;
}
}
PHYSFS_openRead, file is valid.
Any suggestions?
I tried loading the font from file, works fine.