2
\$\begingroup\$

I'm making a text based game using SDL2 and SDL_TTF. I just started working with TTF, and I've noticed there is some kind of character limit regarding how much text you can render at a time! I can only render about 15 characters, after that, (16 characters or higher) the screen is just blank.

I really want to render large bodies of text (multiple sentences at a time) so how do I overcome this issue? For rendering text, I have this function:

void drawDialog(const char* content) {
    //Draws a dialog box with set text

    TTF_Font* font = TTF_OpenFont("assets/times.ttf", 900);
    SDL_Color textColor = { 255, 255, 255 };
    SDL_Surface* message = TTF_RenderText_Solid(font, content, textColor);
    SDL_Texture* tex;

    SDL_Rect destRect;

    destRect.x = 50;
    destRect.y = 730;

    destRect.w = 200;
    destRect.h = 30;

    tex = SDL_CreateTextureFromSurface(renderer, message);
    SDL_FreeSurface(message);
    SDL_RenderCopy(renderer, tex, NULL, &destRect);
    SDL_RenderPresent(renderer);
}

So, any advice for overcoming this limit? Any help would be greatly appreciated!

\$\endgroup\$
2
\$\begingroup\$

You're probably running into surface/texture size issues, since you're loading the font in a massive size (900). I'd suggest using a much smaller point size, and that should look just as good as you don't necessarily need to downscale it at all.

I render fonts with sizes around 30 for smaller text, and around 50 for larger menu text.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.