Jump to content
  • Advertisement
Sign in to follow this  

SDL TTF text rendering help

This topic is 3859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've only recently started tinkering with Cpp and SDL and I've been using the Lazy Foo tutorials. I'm trying to make a message box function for a game I'm working on. Basically it would take a string, send it to the function, and the function would display it on screen with a fancy border around the box and a black somewhat see-thru background. Well, last night I spent about 4 hours making this function.. which works, but I can't help thinking there had to be an easier way to do it. My function would take the string, add one character at a time from it to an SDL_Surface using TTF_RenderText_Solid until that surface was too wide for the box, go back thru the string til it found a space, re-apply those characters to the surface (up to the space), then make another surface in the same manner containing the next part of the string, and another 2 surfaces after that. The function would then blit the message box background (alpha'd black surface) to the screen, then the border, then the sufaces containing the lines of text one under another. It turned out pretty well... but I'm hoping someone will tell me I put way too much effort into it. I've looked thru some of the docuentation but didn't see anything that might help, is there some way to use the text rendering functions to keep the returned surface within specific height and width requirements, and word-wrapping long strings around to a new line of text in the surface? My function does this surface1 - This would be the first part of the string surface2 - passed to my function. But it took way too surface3 - much effort. surface4 - blank surface rendered with ' ' char I want it to return one surface that is the same as the above 4 surfaces stacked on eachother Any clever ideas, or something I've missed? I'd be glad to post my code so you can see what I did and help me make it better. (If someone could tell me how to post code, i've noticed I can't post certain characters like the 'plus sign' on here) Thanks

Share this post


Link to post
Share on other sites
Advertisement
Split text into lines. Then, split lines into words. You don't need to check it for each letter, since you won't split a word in the middle.

Share this post


Link to post
Share on other sites
OK, thanks, that makes sense, rather than working with individual characters I should have worked with words. So, there's no way for TTF_RenderText functions to automatically split it to different lines and return just one SDL_Surface with more than one line of text staying within given surface width requirements?

Again, thanks for the idea.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!