Hi, I'm trying to load a font from memory, because I plan to use a custom font file type in the future already used in my engine.
Right now, though, I'm just trying to load a file into a std::string, and then use font.LoadFromFile( ) to get the font.
This is the code I'm using:
std::string& OpenFile( std::string filename )
{
int length;
char* buffer;
std::string* encrypted;
std::ifstream file;
file.open( filename.c_str( ), std::ios::binary | std::ios::ate );
file.seekg( 0, std::ios::end );
length = file.tellg( );
file.seekg( 0, std::ios::beg );
buffer = new char[ length ];
file.read( buffer, length );
file.close( );
*encrypted = buffer;
delete( buffer );
return( *encrypted );
}
And this is the code I use to load the font:
sf::Font font;
std::string file = OpenFile( "Arial.ttf" );
font.LoadFromMemory( file.c_str( ), file.length( ) );
The file is valid, and the error I get from SFML is an invalid stream operation.
Any help is appreciated.