Jump to content
  • Advertisement
Sign in to follow this  
vman

sdl & text width

This topic is 4544 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

Hi all , i have a simple question to ask about sdl. I've got this code:
Quote:
int px,py=0; px = 100; py = 220; message = TTF_RenderText_Blended(font_name, "text text text -.- -.- ..023adasdadasdadadasddasdasad", txt_col ); if( message == NULL ) { return 1; } else { UPDATE_POSITION( px, py, message, screen ); }
The problem with the above code is that my text message's width is greater than the window's client width and it doesnt displays the text in the right order. What i want , is a function(maybe?) that can get the width of my text object. I know the math formula , wich is: x = (SCREEN WIDTH / 2) - (TEXT OBJECT WIDTH / 2) & y = (SCREEN HEIGHT / 2) - (TEXT OBJECT HEIGHT / 2) but i dont know how to get the text object's width. Any ideas??

Share this post


Link to post
Share on other sites
Advertisement
Also, TTF_RenderText_Foo(...) returns a SDL_Surface. You can access that surface's width and height with it's members 'w' and 'h':

SDL_Surface *p = TTF_RenderText_Solid(...);

int x = (sw / 2) - (p->w / 2);
int y = (sh / 2) - (p->h / 2);

Share this post


Link to post
Share on other sites
Thanks "agi_shi" & "TravisWells" for the nice examples!
Finally i made it to work!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!