-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextSurface.h
46 lines (36 loc) · 913 Bytes
/
TextSurface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*****************************************************************************
Yihsiang Liow
Copyright
*****************************************************************************/
#ifndef TEXTSURFACE_H
#define TEXTSURFACE_H
#include "Color.h"
class TextSurface
{
public:
TextSurface(const char str[]="Hello, World!",
const char fontfamily[]="arial.ttf", int size=12, int R=255, int G=255, int B=255 )
{
atexit( TTF_Quit );
if ( TTF_Init() != 0 )
{
printf("TTF_Init: %s\n", TTF_GetError());
return;
}
TTF_Font * font = TTF_OpenFont( fontfamily, size );
Color color = {Uint8(R), Uint8(G), Uint8(B)};
text = TTF_RenderText_Solid( font, str, color );
TTF_CloseFont( font );
}
~TextSurface()
{
SDL_FreeSurface( text );
}
SDL_Surface * get_surface()
{
return text;
}
private:
SDL_Surface * text;
};
#endif