Skip to content

Commit df40156

Browse files
committed
feat: basic tutorial code
1 parent 959ce95 commit df40156

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ find_package(SDL2_image REQUIRED)
1111
find_package(SDL2_ttf REQUIRED)
1212

1313

14-
add_executable(${PROJECT_NAME} src/gamedev_env.cpp src/main.cpp)
14+
add_executable(${PROJECT_NAME} src/main.cpp)
1515

1616
target_link_libraries(${PROJECT_NAME} Bullet::Bullet)
1717
target_link_libraries(${PROJECT_NAME} Vulkan::Vulkan)

src/main.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <SDL2/SDL.h>
44
#include <SDL2/SDL_timer.h>
55
#include <SDL2/SDL_image.h>
6-
#include <SDL2/SDL2_ttf>
6+
#include <SDL2/SDL_ttf.h>
77
#include <iostream>
88

99
// TODO: fix docker contaeinr env
@@ -35,6 +35,7 @@ void render_text(
3535

3636
int main(int argc, char *argv[])
3737
{
38+
3839
// returns zero on success else non-zero
3940
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
4041
{
@@ -63,7 +64,7 @@ int main(int argc, char *argv[])
6364
try
6465
{
6566
// please provide a path for your image
66-
surface = IMG_Load("../15212165.png");
67+
surface = IMG_Load("../Conan_package_manager_logo.png");
6768
}
6869
catch (const std::exception &e)
6970
{
@@ -113,7 +114,13 @@ int main(int argc, char *argv[])
113114
///
114115
/// Section 4: SDL ttf and rendering text
115116
///
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+
}
117124
///
118125
/// Section 3: Game Loop and Basic Controls
119126
/// Note: The rest of this snippet will be removed
@@ -172,18 +179,24 @@ int main(int argc, char *argv[])
172179
if (dest.y < 0)
173180
dest.y = 0;
174181

175-
// clears the screen
176-
SDL_RenderClear(rend);
177-
SDL_RenderCopy(rend, tex, NULL, &dest);
178-
179182
///
180183
/// Section 4: SDL ttf and rendering text
181184
///
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);
182193

183194
// triggers the double buffers
184195
// for multiple rendering
185196
SDL_RenderPresent(rend);
186-
197+
// clears the screen
198+
SDL_RenderClear(rend);
199+
SDL_RenderCopy(rend, tex, NULL, &dest);
187200
// calculates to 60 fps
188201
SDL_Delay(1000 / 60);
189202
}
@@ -195,6 +208,17 @@ int main(int argc, char *argv[])
195208
///
196209
/// Section 5: Freeing resources
197210
///
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);
198222
///
199223
/// Section 4: SDL ttf and rendering text
200224
///

start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def a():
9-
subprocess.run(["docker", "build", "--tag", "game_dev_env_image:0.1v", "."])
9+
# subprocess.run(["docker", "build", "--tag", "game_dev_env_image:0.1v", "."])
1010

1111
dir = os.getcwd().replace("\\", "/")
1212
mounting = f"{dir}/src:/workdir/dep/src"
@@ -21,7 +21,7 @@ def a():
2121
"-v",
2222
mounting,
2323
"-d",
24-
"sullmeister/game_env_container:0.1v",
24+
"sullmeister/game_env_container:0.2v", # make the tag version editable manualy in the future
2525
]
2626
)
2727

0 commit comments

Comments
 (0)