@@ -367,13 +367,29 @@ void UI::exitApp() {
367367* UI draw functions
368368*/
369369void 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+
377393void 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