0

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?

Vogel612
  • 5,620
  • 5
  • 48
  • 73
TPS
  • 2,067
  • 3
  • 23
  • 32
  • Read the file into memory, close file, use memory. –  Mar 30 '13 at 18:55
  • @Armin I was under the impression that when you release a font in SDL_ttf using TTF_CloseFont(TTF_Font *font) the font file is closed but the font itself is also removed from memory so could not be used after. – TPS Mar 30 '13 at 19:13
  • 2
    I was just generalizing. You didn't write what function you're using but `TTF_OpenFont ` for example doesn't leave the file open; maybe your confusing memory and file on the disk. –  Mar 30 '13 at 19:16
  • Ah OK, that clears it up for me. Yes I was referring to the file on disk and if TTF_OpenFont doesn't hold the file open then all is good. – TPS Mar 30 '13 at 19:36

1 Answers1

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

TPS
  • 2,067
  • 3
  • 23
  • 32