title: How do find out the width and height of the text without using surface in SDL2?
body: <p>I wanted to create a separate function where I could just send a string and it will render the text appropriately so that I didn't need to copy-paste same stuff. The function I came up with is in the following.</p>
  
  <pre class="lang-c prettyprint-override"><code>void renderText(SDL_Renderer* renderer, char* text,
                  char* font_name, int font_size,
                  SDL_Color color, SDL_Rect text_area)
  {
      /* If TTF was not initialized initialize it */
      if (!TTF_WasInit()) {
          if (TTF_Init() &lt; 0) {
              printf("Error initializing TTF: %s\n", SDL_GetError());
              return EXIT_FAILURE;
          }
      }
  
      TTF_Font* font = TTF_OpenFont(font_name, font_size);
      if (font == NULL) {
          printf("Error opening font: %s\n", SDL_GetError());
          return;
      }
  
      SDL_Surface* surface = TTF_RenderText_Blended(font, text, color);
      SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
      if (!texture) {
          printf("error creating texture: %s\n", SDL_GetError());
          TTF_CloseFont(font);
          return;
      }
  
      SDL_RenderCopy(renderer, message, NULL, &amp;text_area);
  
      SDL_FreeSurface(surface);
      SDL_DestroyTexture(texture);
      TTF_CloseFont(font);
  
  }
  </code></pre>
  
  <p>Now, sometimes I want to align the text with the window for which I need to know the height and width of the surface that contains the text so that I can use something like <code>(WINDOW_WIDTH - surfaceText-&gt;w) / 2</code> or <code>(WINDOW_HEIGHT - surfaceText-&gt;h) / 2</code>. But there is no way to know the height and width of the surface containing the text without creating the surface. And if I end up needing to create the surface then the separation of this function would not live upto its objective.</p>
  
  <blockquote>
    <p>How do I find out the height and width of the surface containing the text without actually creating the surface in SDL2_ttf library?</p>
  </blockquote>