Skip to main content
added 161 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a TextRenderingCache class to manage cached font renderings. It usually has a hash table with string plus render settings (font, color, size, etc.) as key and a texture with the rendering as value. When a given rendering is requested from the TextRenderingCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

By the way: FreeType already comes with a rendering cache system. But it is only used when you use it explicitly.

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a TextRenderingCache class to manage cached font renderings. It usually has a hash table with string plus render settings (font, color, size, etc.) as key and a texture with the rendering as value. When a given rendering is requested from the TextRenderingCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a TextRenderingCache class to manage cached font renderings. It usually has a hash table with string plus render settings (font, color, size, etc.) as key and a texture with the rendering as value. When a given rendering is requested from the TextRenderingCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

By the way: FreeType already comes with a rendering cache system. But it is only used when you use it explicitly.

added 18 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a FontCacheTextRenderingCache class to manage cached font renderings. It usually has a hash table with string plus render settings (font, color, size, etc.) as key and a texture with the rendering as value. When a given rendering is requested from the FontCacheTextRenderingCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a FontCache class to manage cached font renderings. It usually has a hash table with string plus render settings as key and a texture with the rendering as value. When a given rendering is requested from the FontCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a TextRenderingCache class to manage cached font renderings. It usually has a hash table with string plus render settings (font, color, size, etc.) as key and a texture with the rendering as value. When a given rendering is requested from the TextRenderingCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

added 62 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a FontCache class to manage cached font renderings. It usually has a hash table with string plus render settings as key and a texture with the rendering as value. When a given rendering is requested from the FontCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the screen unchanged for at least a few seconds.

When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering the text. When you do this, the cost of text-rendering will only apply the first time you need to render a given string with given settings. On any subsequent frame, the cost of displaying that string is the same as for drawing any other sprite of that size.

A solution which I found quite handy in various projects was to have a FontCache class to manage cached font renderings. It usually has a hash table with string plus render settings as key and a texture with the rendering as value. When a given rendering is requested from the FontCache class, it checks if it already has that rendering, and if not it creates one. Dropping renderings from the hash-map which were not used for several seconds to avoid memory leakage is optional (some games need this, some do not).

added 62 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading