diff options
Diffstat (limited to 'font.c')
-rw-r--r-- | font.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +#include <SDL2/SDL_error.h> +#include <SDL2/SDL_render.h> +#include <SDL2/SDL_image.h> +#include "font.h" + +extern SDL_Renderer *renderer; +static SDL_Texture *font_tex = NULL; + +int font_init(const char *path) +{ + if ((font_tex = IMG_LoadTexture(renderer, path)) == NULL) + return 1; + return 0; +} + +void font_deinit(void) +{ + if (font_tex != NULL) { + SDL_DestroyTexture(font_tex); + font_tex = NULL; + } +} + +void font_draw(int x, int y, const char *s) +{ + const int ox = x; + for (; *s != '\0'; s++) { + const char c = toupper(*s); + const int ix = c % 16 * FONT_W; + const int iy = c / 16 * FONT_H; + x += 1; + } +} + +void font_set_color(int r, int g, int b, int a) +{ + if (SDL_SetTextureColorMod(font_tex, r, g, b)) + fprintf(stderr, "%s\n", SDL_GetError()); + if (SDL_SetTextureAlphaMod(font_tex, a)) + fprintf(stderr, "%s\n", SDL_GetError()); +} |