1

I have some basics set up in my game but I came to a point where I want to include font rendering (initially for debug output to the screen).

Looking at various tutorials and the SDL_ttf library I require clarification on something. The SDL_ttf will give you an SDL_Surface which you can then create a texture from to allow for hardware rendering. The whole process though requires a font file loading.

My main question is - Is it safe to leave the font file open until the font is no longer needed?

I saw a tutorial which closed the font file immediately after creating the SDL_Texture. My thoughts were if this was used for frequently updated text e.g. a frame rate counter, this would be highly inefficient and it would be better to hold the font file open (assuming there is no negative impact).

And the follow up from this would be if the font file is held open, would it be locked so no other font could use it?

4

1 回答 1

2

From feedback it is now clear that when opening a font file using TTF_OpenFont the file on disk does not remain open. Therefore once the font has been opened it is in memory for use as normal and can then be released with TTF_CloseFont when no longer required.

The initial question was a result of confusion around the file remaining open (or not as it turned out) after the call to TTF_OpenFont

Credit to @Armin for this

于 2013-03-30T19:40:27.283 回答