#ifndef gobjects #define gobjects #include #include #include #define flaot float typedef struct TEXT { SDL_Rect textRect; SDL_Texture *texture; } TEXT; typedef struct GS{ int width; int height; SDL_Renderer *renderer; TTF_Font *font; } GS; TEXT *text_constructor(GS *stuff, char *text_buf){ TEXT *text=(TEXT*)malloc(sizeof(TEXT)); SDL_Color color={ 244,222,205 }; int w, h; TTF_SizeUTF8(stuff->font,text_buf,&w,&h); SDL_Rect textRect={ 0,0,w,h }; textRect.x=(stuff->width/2)-(textRect.w/2); textRect.y=(stuff->height/2)-(textRect.h/2); SDL_Surface *textSurface = TTF_RenderUTF8_Solid_Wrapped(stuff->font, text_buf, color, textRect.w); if(!textSurface){ fprintf(stderr,"ERROR WITH TEXT SURFACE\n"); exit(EXIT_FAILURE); } SDL_Texture *texture = SDL_CreateTextureFromSurface(stuff->renderer, textSurface); SDL_FreeSurface(textSurface); if(!texture){ fprintf(stderr,"ERROR WITH TEXTURE\n"); exit(EXIT_FAILURE); } text->texture=texture; text->textRect=textRect; return text; } #endif