A think the error is on TTF_SizeText(...)
calling. It does not know about the boundary you set and probably ignores endlines too. Try to remove that line an put these instead:
int w, h;
w = surf->w;
h = surf->h;
I hope it helps.
Question
When a string of text goes past say, 300
in length, I want it to drop to a new line and continue. I read that this is how you do it but it's not working - it is just stretching out the text.
How to achieve this?
const char* message = "example text to test that it drops to a new line.";
std::string fontFile = "Font/font.ttf";
int fontSize = 16;
TTF_Font *font = nullptr;
font = TTF_OpenFont(fontFile.c_str(), fontSize);
SDL_Color textColor = { 0, 300, 200 };
SDL_Surface *surf = TTF_RenderText_Blended_Wrapped(font, message, textColor, 300);
texture = SDL_CreateTextureFromSurface(m_p_Renderer, surf);
int w,h;
TTF_SizeText(font,message,&w,&h);
srcRect.x = 0;
srcRect.y = 0;
destRect.x = 0;
destRect.y = 0;
srcRect.w =w;
srcRect.h = h;
destRect.w =w;
destRect.h = h;
Solution
A think the error is on TTF_SizeText(...)
calling. It does not know about the boundary you set and probably ignores endlines too. Try to remove that line an put these instead:
int w, h;
w = surf->w;
h = surf->h;
I hope it helps.