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);