# How to convert font size to pixels?

I'm trying to add text to my game using SDL_TTF, and it's working pretty well.

Except for one thing :

My text's SDL_Surface needs a width and a height, if I don't give it one it will automatically set it to 0, making the text invisible.

However, if I insert a value like 100 width and 100 height, it will stretch the image.

I need to know how I would convert ANY font size on the font arial to pixels in width and height.

• The size of each font is different, I guess you only option is to try a size, get its width and height with TTF_SizeText() and then reduce it or increase it repeatedly – Xriuk Mar 18 '16 at 20:17
• @Xriuk That would not give me a good high and width if the font size were to change during runtime though, right? – BiiX Mar 18 '16 at 20:19
• Are you using surfaces or textures for rendering? – Tyyppi_77 Mar 18 '16 at 21:22
• @BiiX You could implement this into a function, and then call it whenever your font changes size – Xriuk Mar 19 '16 at 13:35
• @Tyyppi_77 I'm using textures. – BiiX Mar 19 '16 at 18:15

TTF_RenderText_Solid(font, const char* text, {r, g, b}); renders a surface with text on it. You could just use something like
SDL_Surface* text = TTF_RenderText_Solid(arial, "hi", {r, g, b});