aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-16 20:52:43 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-16 20:52:43 +0100
commit8abc6008880dd9ed0c16a68a126b49f0eb03caa2 (patch)
tree98bf7773f81d9896df6c17a7d662dd6f4380023f /src/crepe/facade/SDLContext.cpp
parent56342ffab9daade7802b015ac83b9c47a8b9b18b (diff)
fonting
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index d1d109c..4e969b9 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -21,6 +21,8 @@
#include "../api/Config.h"
#include "../api/Sprite.h"
#include "../util/Log.h"
+#include "api/Text.h"
+#include "facade/Font.h"
#include "manager/Mediator.h"
#include "SDLContext.h"
@@ -283,6 +285,28 @@ void SDLContext::draw(const RenderContext & ctx) {
angle, NULL, render_flip);
}
+
+void SDLContext::draw_text(const Text & text, const Font & font){
+ SDL_Color color {
+ .r = text.data.text_color.r,
+ .g = text.data.text_color.g,
+ .b = text.data.text_color.b,
+ .a = text.data.text_color.a,
+ };
+ SDL_Surface * font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color);
+ SDL_Texture * font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface);
+ SDL_FreeSurface(font_surface);
+
+ SDL_FRect dstrect {
+ .x = text.offset.x,
+ .y = text.offset.y,
+ .w = text.dimensions.x,
+ .h = text.dimensions.y,
+ };
+ SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, &dstrect , 0 , NULL, SDL_FLIP_NONE);
+ SDL_DestroyTexture(font_texture);
+}
+
void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
const Camera::Data & cam_data = cam.data;