summaryrefslogtreecommitdiff
path: root/gltfview/src/main.c
blob: f7c372c4337f11139c7c5373b81798549cc50ef4 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "game.h"

#include <gfx/gfx_app.h>
#include <log/log.h>

#include <stdlib.h>

static bool init(const GfxAppDesc* desc, void** app_state) {
  Game* game = calloc(1, sizeof(Game));
  if (!game) {
    LOGE("Failed to allocate game state");
    return false;
  }
  if (!game_new(game, desc->argc, desc->argv)) {
    LOGE("Failed to initialize game\n");
    return false;
  }
  *app_state = game;
  return true;
}

static void shutdown(void* app_state) {
  assert(app_state);
  Game* game = (Game*)(app_state);
  game_end(game);
}

static void update(void* app_state, double t, double dt) {
  assert(app_state);
  Game* game = (Game*)(app_state);
  game_update(game, t, dt);
}

static void render(void* app_state) {
  assert(app_state);
  Game* game = (Game*)(app_state);
  game_render(game);
}

static void resize(void* app_state, int width, int height) {
  assert(app_state);
  Game* game = (Game*)(app_state);
  game_set_viewport(game, width, height);
}

int main(int argc, const char** argv) {
  const int initial_width = 1350;
  const int initial_height = 900;
  const int max_fps = 60;

  gfx_app_run(&(GfxAppDesc){.argc = argc,
                            .argv = argv,
                            .width = initial_width,
                            .height = initial_height,
                            .max_fps = max_fps,
                            .update_delta_time =
                                max_fps > 0 ? 1.0 / (double)max_fps : 0.0},
              &(GfxAppCallbacks){.init = init,
                                 .update = update,
                                 .render = render,
                                 .resize = resize,
                                 .shutdown = shutdown});

  return 0;
}