renderTextDirect

This commit is contained in:
2016-05-10 17:20:16 +10:00
parent 879970abd3
commit e892fcd32c
2 changed files with 13 additions and 3 deletions
+10 -1
View File
@@ -23,7 +23,7 @@
#include <stdexcept> #include <stdexcept>
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) //make the surface (from SDL_ttf)
SDL_Surface* surface = TTF_RenderUTF8_Blended(font, str.c_str(), color); SDL_Surface* surface = TTF_RenderUTF8_Blended(font, str.c_str(), color);
if (!surface) { if (!surface) {
@@ -44,3 +44,12 @@ SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, SDL_Color
//NOTE: free the texture yourself //NOTE: free the texture yourself
return texture; return texture;
} }
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);
}
+2 -1
View File
@@ -26,4 +26,5 @@
#include <string> #include <string>
SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string); 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);