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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include <iostream>
#include <SDL.h>
#include <SDL_ttf.h>
using std::cerr;
using std::endl;
int main(int argc, char* args[])
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
cerr << "SDL_Init() Failed: " << SDL_GetError() << endl;
system ("pause");
exit(1);
}
SDL_Surface* display;
display = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (display == NULL)
{
cerr << "SDL_SetVideoMode() Failed: " << SDL_GetError() << endl;
system ("pause"); exit(1);
}
SDL_WM_SetCaption("SDL Tutorial", "SDL Tutorial");
if (TTF_Init() != 0)
{
cerr << "TTF_Init() Failed: " << TTF_GetError() << endl;
SDL_Quit();
system ("pause");
exit(1);
}
TTF_Font *font;
font = TTF_OpenFont("Data/arial.ttf", 24);
if (font == NULL)
{
cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl;
TTF_Quit();
SDL_Quit();
system ("pause");
exit(1);
}
SDL_Surface *text;
SDL_Color text_color = {255, 255, 255};
text = TTF_RenderText_Solid(font, "A journey of a thousand miles begins with a single step.", text_color);
if (text == NULL)
{
cerr << "TTF_RenderText_Solid() Failed: " << TTF_GetError() << endl;
TTF_Quit();
SDL_Quit();
system ("pause");
exit(1);
}
SDL_Event event;
while(1)
{
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
break;
}
}
if (SDL_FillRect(display, NULL, SDL_MapRGB( display->format, 0,0,0)) != 0)
{
cerr << "SDL_FillRect() Failed: " << SDL_GetError() << endl;
system ("pause");
break;
}
if (SDL_BlitSurface(text, NULL, display, NULL) != 0)
{
cerr << "SDL_BlitSurface() Failed: " << SDL_GetError() << endl; //Diese Fehlermeldung wird immer ausgegeben
system ("pause");
break;
}
SDL_Flip(display);
SDL_FreeSurface (display);
}
TTF_Quit();
SDL_Quit();
return 0;
}
|