aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index e4dadc0..ee291a7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -230,6 +230,18 @@ int main() {
SDL_SetWindowTitle(window, "Showdown of the Sticks");
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
+ if (TTF_Init() == -1) {
+ std::cerr << "TTF_Init failed: " << TTF_GetError() << std::endl;
+ return 1;
+ }
+
+ globalFont = TTF_OpenFont("assets/fonts/OpenSans-Regular.ttf", 24);
+ if (!globalFont) {
+ std::cerr << "Failed to load font: " << TTF_GetError() << std::endl;
+ return 1;
+ }
+
+
if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) {
std::cerr << "Failed to initialize SDL_image: " << IMG_GetError() << std::endl;
return 1;
@@ -265,7 +277,7 @@ int main() {
} else {
lua_pop(L, 1);
}
-
+ SDL_Delay(25);
}
}
}
@@ -302,6 +314,25 @@ int main() {
for (const auto& button: buttonList) {
SDL_SetRenderDrawColor(renderer, 252, 210, 77, 255);
SDL_RenderFillRect(renderer, &button.rect);
+ if (globalFont) {
+ SDL_Color white = {255, 255, 255, 255};
+ SDL_Surface* textSurface = TTF_RenderText_Blended(globalFont, button.text.c_str(), white);
+ if (textSurface) {
+ SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
+ SDL_Rect textRect;
+ textRect.w = textSurface->w;
+ textRect.h = textSurface->h;
+ textRect.x = button.rect.x + (button.rect.w - textRect.w) / 2;
+ textRect.y = button.rect.y + (button.rect.h - textRect.h) / 2;
+
+ SDL_FreeSurface(textSurface);
+
+ if (textTexture) {
+ SDL_RenderCopy(renderer, textTexture, nullptr, &textRect);
+ SDL_DestroyTexture(textTexture);
+ }
+ }
+ }
}