aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/font.c
blob: 76cb16026a8fad547431b26dbf261bb380227976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <SDL.h>
#include <SDL_ttf.h>
#include "font.h"
#include "util.h"

TTF_Font *
font_load(
  const asset_id_t font_asset_id,
  const int font_size
) {
  // get asset
  const asset_t * const asset = asset_get(font_asset_id);
  if (!asset) {
    die("asset_get()");
  }

  // create io
  SDL_RWops *rw = SDL_RWFromConstMem(asset->buf, asset->len);
  if (!rw) {
    die("SDL_RWFromConstMem(): %s", SDL_GetError());
  }

  // load font
  TTF_Font *font = TTF_OpenFontIndexRW(rw, 1, font_size, 0);
  if (!font) {
    die("TTF_OpenFontIndex(): %s", TTF_GetError());
  }

  // return font
  return font;
}