Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MatVGL::FontData MatVGL::VFonts::createString(MatVGL_Font font, String *text,
- Int16 r, Int16 g, Int16 b) {
- // Put the given colors into SDL_Color, making sure they are between 0 and
- // 255.
- if (r < 0)
- r = 0;
- if (g < 0)
- g = 0;
- if (b < 0)
- b = 0;
- if (r > 255)
- r = 255;
- if (g > 255)
- g = 255;
- if (b > 255)
- b = 255;
- SDL_Color fontColor{(unsigned char)r, (unsigned char)g, (unsigned char)b,
- 255};
- // Create the surface with the given data.
- SDL_Surface *fontSurface =
- TTF_RenderText_Solid(p_fontsMap.find(font)->second, text, fontColor);
- // Put all the data into the structure.
- FontData fontData = {(UInt32)fontSurface->w, (UInt32)fontSurface->h,
- fontSurface->pixels};
- // We have to free the surface.
- SDL_FreeSurface(fontSurface);
- // Return the surface data.
- return fontData;
- }
- ////////// Fonts.h ↓
- typedef struct FontData {
- UInt32 w;
- UInt32 h;
- void *data;
- } FontData;
Advertisement
Add Comment
Please, Sign In to add comment