convotest/tools.c
2024-06-15 16:56:16 -05:00

33 lines
718 B
C

#include<assert.h>
#include<inttypes.h>
#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<time.h>
#include<SDL2/SDL.h>
#include<SDL2/SDL_ttf.h>
#include<SDL2/SDL_image.h>
#include"tools.h"
void print_text(SDL_Renderer*ren,TTF_Font*font,int color,int x,int y,const char*str)
{
SDL_Color c=(SDL_Color){
.r=(color>>16)&0xff,
.g=(color>>8)&0xff,
.b=(color>>0)&0xff,
.a=0xff,
};
SDL_Surface*surface=TTF_RenderText_Solid(font,str,c);
SDL_Texture*texture=SDL_CreateTextureFromSurface(ren,surface);
SDL_Rect rect={.x=x,.y=y,.w=surface->w,.h=surface->h};
SDL_RenderCopy(ren,texture,NULL,&rect);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
}