aboutsummaryrefslogtreecommitdiff
path: root/lib/gobjects.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gobjects.c')
-rw-r--r--lib/gobjects.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/gobjects.c b/lib/gobjects.c
new file mode 100644
index 0000000..0817181
--- /dev/null
+++ b/lib/gobjects.c
@@ -0,0 +1,51 @@
+#ifndef gobjects
+#define gobjects
+
+#include <stdlib.h>
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_ttf.h>
+
+#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