Skip to content

Commit 94ca668

Browse files
authored
Merge pull request #13 from D3fau4/master
fixed bad compilation problem
2 parents 5799b30 + f759351 commit 94ca668

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

source/UI.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,29 @@ void UI::exitApp() {
367367
* UI draw functions
368368
*/
369369
void UI::drawText(int x, int y, SDL_Color scolor, string text, TTF_Font *font) {
370-
SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped(font, text.c_str(), scolor, 1280);
371-
SDL_SetSurfaceAlphaMod(surface, 255);
372-
SDL_Rect position = { x, y, surface->w, surface->h };
373-
SDL_BlitSurface(surface, NULL, mRender._surface, &position);
374-
SDL_FreeSurface(surface);
370+
SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped(font, text.c_str(), scolor, 1280);
371+
372+
if (!surface) {
373+
return;
374+
}
375+
376+
SDL_SetSurfaceAlphaMod(surface, 255);
377+
SDL_Texture *texture = SDL_CreateTextureFromSurface(mRender._renderer, surface);
378+
379+
if (texture) {
380+
SDL_Rect position;
381+
position.x = x;
382+
position.y = y;
383+
position.w = surface->w;
384+
position.h = surface->h;
385+
386+
SDL_RenderCopy(mRender._renderer, texture, NULL, &position);
387+
SDL_DestroyTexture(texture);
388+
}
389+
SDL_FreeSurface(surface);
375390
}
376391

392+
377393
void UI::drawRect(int x, int y, int w, int h, SDL_Color scolor, unsigned border, SDL_Color bcolor) {
378394
drawRect(x-border, y-border, w+(2*border), h+(2*border), bcolor);
379395
drawRect(x, y, w, h, scolor);

0 commit comments

Comments
 (0)