Domanda

My application does some text output with OpenGL and FTGL. I set up a font like this:

Impl::font = new FTTextureFont("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
if (Impl::font->Error() != 0) {
    delete Impl::font;
    throw std::runtime_error("Could not load font DejaVuSans.ttf!");
}
if (!Impl::font->FaceSize(72)) {
    delete Impl::font;
    throw std::runtime_error("Could not use DejaVuSans with size 72!");
}

I render like this:

glColor3f(1.0, 1.0, 1.0);
Impl::font->Render(my_string.c_str());

Now I have a major problem: There is one string which I create pretty early in the program, which renders correctly. Then there's another string which gets created later, and it renders only those letters which are also contained in the first string. I can only assume that the texture font does only create textures for the letters of the first string, but not for those of the second string.

What could be the cause for this? Do I need to make it load all characters I will use early? Is there something I'm missing?

(It would be quite some effort to boil my code down to a minimal example that reproduces the error, so I ask first for something obvious I'm doing wrong.)

È stato utile?

Soluzione

I found the cause: I called Impl::font->BBox(my_string.c_str()) somewhere else in the code. Apparently, this leads to rendering the string as texture and caching it. Now because this code was called from another thread, it could not load the missing characters. As soon as I moved the BBox calculation to the render thread, everything worked just fine.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top