From e892fcd32cc917da2fa2aeb23b634839e197e3c0 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 10 May 2016 17:20:16 +1000 Subject: [PATCH] renderTextDirect --- render_text_texture.cpp | 13 +++++++++++-- render_text_texture.hpp | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/render_text_texture.cpp b/render_text_texture.cpp index 4b9d127..b865118 100644 --- a/render_text_texture.cpp +++ b/render_text_texture.cpp @@ -23,7 +23,7 @@ #include -SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string str) { +SDL_Texture* renderTextTexture(SDL_Renderer* const renderer, TTF_Font* font, SDL_Color color, std::string str) { //make the surface (from SDL_ttf) SDL_Surface* surface = TTF_RenderUTF8_Blended(font, str.c_str(), color); if (!surface) { @@ -43,4 +43,13 @@ SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, SDL_Color //NOTE: free the texture yourself return texture; -} \ No newline at end of file +} + +void renderTextDirect(SDL_Renderer* const renderer, TTF_Font* font, SDL_Color color, std::string str, int x, int y) { + int w = 0, h = 0; + SDL_Texture* tmpTex = renderTextTexture(renderer, font, color, str); + SDL_QueryTexture(tmpTex, nullptr, nullptr, &w, &h); + SDL_Rect dclip = {x, y, w, h}; + SDL_RenderCopy(renderer, tmpTex, nullptr, &dclip); + SDL_DestroyTexture(tmpTex); +} diff --git a/render_text_texture.hpp b/render_text_texture.hpp index 1aca1ed..db226a7 100644 --- a/render_text_texture.hpp +++ b/render_text_texture.hpp @@ -26,4 +26,5 @@ #include -SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string); \ No newline at end of file +SDL_Texture* renderTextTexture(SDL_Renderer* const, TTF_Font*, SDL_Color color, std::string); +void renderTextDirect(SDL_Renderer* const renderer, TTF_Font* font, SDL_Color color, std::string str, int x, int y);