Jump to content
  • Advertisement
Sign in to follow this  
Alpha Nox


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

Hello, I'm using the following function to write text with SDL_TTf: void drawtext(char* text,int x,int y,int size,int fR,int fG, int fB, int bR, int bG, int bB){ TTF_Font* font = TTF_OpenFont("ARIAL.TTF", size); // font name,font size SDL_Color foregroundColor = { fR, fG, fB }; SDL_Color backgroundColor = { bR, bG, bB }; SDL_Surface* textSurface = TTF_RenderText_Shaded(font, text, foregroundColor, backgroundColor); SDL_SetColorKey(textSurface, SDL_SRCCOLORKEY, SDL_MapRGB(textSurface->format, 255, 0, 255) ); int textwidth,textheight; if (size == 12) {textwidth = 32;textheight = 32;} else if(size == 14) {textwidth = 40;textheight = 40;} else if(size == 16) {textwidth = 50;textheight = 50;} else if(size == 18) {textwidth = 55;textheight = 55;} else if(size == 36) {textwidth = 100;textheight = 100;} SDL_Rect textLocation = { x, y, textwidth, textheight }; // 0, 0 - draw whole surface SDL_BlitSurface(textSurface, NULL, screen, &textLocation); SDL_FreeSurface(textSurface); TTF_CloseFont(font); } But, how do I display an integer? Is there a way to convert INT to char*? Thanks for your help, Victor Freire

Share this post

Link to post
Share on other sites
may I just say man, UNTITLED says it all...

but on a more serious note heres the function I wrote when using SDL_ttf for displaying intigers

Uint8 Draw_Text(char* FILE_NAME,int WriteA,int x,int y,int Size)
char Write[50];
sprintf(Write, "%d\0", WriteA);
SDL_Rect Draw_At = {x,y,0,0};
TTF_Font *FONT = TTF_OpenFont(FILE_NAME,Size);
SDL_Color clrFg = {255,255,255,0};
SDL_Surface *sText = TTF_RenderText_Blended( FONT, Write, clrFg );
TTF_CloseFont( FONT );
SDL_FreeSurface( sText );
return sText->w;

you can play with it how u like its definetly not efficient but it will get the job done and there ist really and overhead to calling it.

FILE_NAME = your font file path
WriteA = the int your writing
x and y coordaninths
Size = font SIZE

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!