3
3
#include < SDL2/SDL.h>
4
4
#include < SDL2/SDL_timer.h>
5
5
#include < SDL2/SDL_image.h>
6
- #include < SDL2/SDL2_ttf >
6
+ #include < SDL2/SDL_ttf.h >
7
7
#include < iostream>
8
8
9
9
// TODO: fix docker contaeinr env
@@ -35,6 +35,7 @@ void render_text(
35
35
36
36
int main (int argc, char *argv[])
37
37
{
38
+
38
39
// returns zero on success else non-zero
39
40
if (SDL_Init (SDL_INIT_EVERYTHING) != 0 )
40
41
{
@@ -63,7 +64,7 @@ int main(int argc, char *argv[])
63
64
try
64
65
{
65
66
// please provide a path for your image
66
- surface = IMG_Load (" ../15212165 .png" );
67
+ surface = IMG_Load (" ../Conan_package_manager_logo .png" );
67
68
}
68
69
catch (const std::exception &e)
69
70
{
@@ -113,7 +114,13 @@ int main(int argc, char *argv[])
113
114
// /
114
115
// / Section 4: SDL ttf and rendering text
115
116
// /
116
-
117
+ TTF_Init ();
118
+ TTF_Font *font = TTF_OpenFont (" ../Roboto-Regular.ttf" , 48 );
119
+ if (font == NULL )
120
+ {
121
+ printf (" error initializing TTF: %s\n " , TTF_GetError ());
122
+ return 1 ;
123
+ }
117
124
// /
118
125
// / Section 3: Game Loop and Basic Controls
119
126
// / Note: The rest of this snippet will be removed
@@ -172,18 +179,24 @@ int main(int argc, char *argv[])
172
179
if (dest.y < 0 )
173
180
dest.y = 0 ;
174
181
175
- // clears the screen
176
- SDL_RenderClear (rend);
177
- SDL_RenderCopy (rend, tex, NULL , &dest);
178
-
179
182
// /
180
183
// / Section 4: SDL ttf and rendering text
181
184
// /
185
+ SDL_Rect text_rect;
186
+
187
+ // The color for the text we will be displaying
188
+ SDL_Color white = {255 , 255 , 255 , 0 };
189
+
190
+ // so we can have nice text, two lines one above the next
191
+ render_text (rend, 10 , 10 , " Hello World!" , font, &text_rect, &white);
192
+ render_text (rend, 10 , text_rect.y + text_rect.h , " Conan demo by JFrog" , font, &text_rect, &white);
182
193
183
194
// triggers the double buffers
184
195
// for multiple rendering
185
196
SDL_RenderPresent (rend);
186
-
197
+ // clears the screen
198
+ SDL_RenderClear (rend);
199
+ SDL_RenderCopy (rend, tex, NULL , &dest);
187
200
// calculates to 60 fps
188
201
SDL_Delay (1000 / 60 );
189
202
}
@@ -195,6 +208,17 @@ int main(int argc, char *argv[])
195
208
// /
196
209
// / Section 5: Freeing resources
197
210
// /
211
+ // close font handle
212
+ TTF_CloseFont (font);
213
+
214
+ // close TTF
215
+ TTF_Quit ();
216
+
217
+ // destroy texture
218
+ SDL_DestroyTexture (tex);
219
+
220
+ // destroy renderer
221
+ SDL_DestroyRenderer (rend);
198
222
// /
199
223
// / Section 4: SDL ttf and rendering text
200
224
// /
0 commit comments