Sign in to follow this  

sdl & text width

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

This topic is 4202 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this