rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

load font from memory fails #163

Closed skanti closed 7 years ago

skanti commented 7 years ago

I load a ttf as binary as

static void load_all_bytes_from_file(std::string filename, std::vector<char> &buffer, int &buffer_size) {
    std::ifstream ifs(filename, std::ios::binary| std::ios::ate);
    std::ifstream::pos_type pos = ifs.tellg();

    buffer.resize(pos);
    buffer_size = (int)pos;

    ifs.seekg(0, std::ios::beg);
    ifs.read(&buffer[0], pos);
}

Then I provide that buffer to

texture_font_new_from_memory(atlas, 28, buffer.data(), buffer.size());

but it will break down at

FT_Load_Glyph

Any thoughts? I assume I am supposed to load it differently?

rougier commented 7 years ago

Did you solve it in the end ?

skanti commented 7 years ago

Yes, the problem was that the buffer has to remain alive throughout the run-time. I deallocated it after the first use which caused problems at loadings. Maybe you should mention it somewhere in your documentation:)

rougier commented 7 years ago

PR welcome !