Advertisement
Mohamed_AIT_RAMI

drawText

Jan 28th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. void drawText(int x, int y, int r, int g, int b, char *format, ...)
  2. {
  3.     int i, len, c;
  4.     SDL_Rect rect;
  5.     va_list args;
  6.  
  7.     memset(&drawTextBuffer, '\0', sizeof(drawTextBuffer));
  8.  
  9.     va_start(args, format);
  10.     vsprintf(drawTextBuffer, format, args);
  11.     va_end(args);
  12.  
  13.     len = strlen(drawTextBuffer);
  14.  
  15.     rect.w = GLYPH_WIDTH;
  16.     rect.h = GLYPH_HEIGHT;
  17.     rect.y = 0;
  18.  
  19.     SDL_SetTextureColorMod(fontTexture, r, g, b);
  20.  
  21.     for (i = 0 ; i < len ; i++)
  22.     {
  23.         c = drawTextBuffer[i];
  24.  
  25.         if (c >= ' ' && c <= 'Z')
  26.         {
  27.             rect.x = (c - ' ') * GLYPH_WIDTH;
  28.  
  29.             blitRect(fontTexture, &rect, x, y);
  30.  
  31.             x += GLYPH_WIDTH;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement