SFML community forums
Help => General => Topic started by: Elgan on February 14, 2012, 02:45:00 pm
-
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.
-
Does font.LoadFromStream return false? What does "fontstream returns TRUE and not NULL" mean?
Can I see the complete implementation of the sf::physfs class?
One thing that you will need to fix, after loading works, is that the font source (in this case the stream -- or just its contents, I don't remember) has to remain alive as long as the font is used for drawing. This is because I cannot preload all the font's glyphs directly in the LoadFromXxx function, it is done on the fly.
-
Does font.LoadFromStream return false?
.
it returns false.
What does "fontstream returns TRUE and not NULL" mean?
.
I mean, the file has a handle and the error section of the class is false, So I mean it reports it as loading "correctly"
here is an image to illustrate what I mean;
http://i41.tinypic.com/qn787d.png
Can I see the complete implementation of the sf::physfs class?
.
I am using the following code:
https://github.com/SFML/SFML/wiki/SourceSfmlPhysfs
Its header is simply
namespace sf{
class physfs: public sf::InputStream{
private:
PHYSFS_File *file;
public:
mutable bool error;
public:
physfs(const char *);
~physfs();
sf::Int64 Read(char *, sf::Int64);
sf::Int64 Seek(sf::Int64);
sf::Int64 Tell();
sf::Int64 GetSize();
};
}
One thing that you will need to fix, after loading works, is that the font source (in this case the stream -- or just its contents, I don't remember) has to remain alive as long as the font is used for drawing. This is because I cannot preload all the font's glyphs directly in the LoadFromXxx function, it is done on the fly
.
I see, thank you
-
Your implementation of Seek is incorrect, you return a status (see the doc of PHYSFS_seek) but sf::InputStream::Seek must return the new position.
You should tell the class writer (if it's not you) so that he can correct its class and reupload it on the wiki. Too bad he didn't paste this tiny code directly on the wiki page, so that anyone can edit it.
And please resize your screenshot, it's too wide.
-
yeah I'm sorry about the screenshot, it turned up a lot bigger than I thought, I assumed the link would be a thumbnail.
int PHYSFS_seek ( PHYSFS_File * handle,
PHYSFS_uint64 pos
)
I returned the same position and it seems to work well. thank you, I will let the author know..
amazingly spotted.
-
You should check the version used on the wiki example as well as the version you downloaded. If you're using the latest source version, there seem to be several more or less significant changes as well as deprecated functions.
-
You should check the version used on the wiki example as well as the version you downloaded. If you're using the latest source version, there seem to be several more or less significant changes as well as deprecated functions.
May I ask Which?
Everything seems good, I should probably go over and make sure its good, rather than just assuming, thank you
I finally worked out who the Author was, and will notify them of this thread
-
Not without rechecking the headers, but most are marked as "deprecated" or simply missing.
-
Try the fixed version https://legacy.sfmluploads.org/file/89 (https://legacy.sfmluploads.org/file/89)
Link to module fixed at the wiki.
:)
-
thanx v.much for your work!