Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JollyRoger

Pages: 1 [2]
16
Graphics / Load Font from Memory
« on: December 12, 2009, 06:53:02 pm »
Thanks.  I was working with two similar functions, I allocated the string in one, but not the other.

I figured out that one reason it wasn't working was because I was deleting the buffer, so it was trying to access memory that wasn't there.  I ended up just having the function return the buffer instead of a std::string.

Thanks for the help.

17
Graphics / Load Font from Memory
« on: December 12, 2009, 04:40:51 am »
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:
Code: [Select]

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:
Code: [Select]

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.

Pages: 1 [2]
anything