summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: d518632d548d6603555e511a3a5bcd9d5e54753c (plain) (blame)
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
#include "engine.h"
#include "log.h"
#include "platform.h"

int main(void) {
  struct vgltf_platform platform = {};
  if (!vgltf_platform_init(&platform)) {
    VGLTF_LOG_ERR("Platform initialization failed");
    goto err;
  }

  struct vgltf_engine engine = {};
  if (!vgltf_engine_init(&engine, &platform)) {
    VGLTF_LOG_ERR("Couldn't initialize the engine");
    goto deinit_platform;
  }

  VGLTF_LOG_INFO("Starting main loop");
  while (true) {
    struct vgltf_event event;
    while (vgltf_platform_poll_event(&platform, &event)) {
      if (event.type == VGLTF_EVENT_QUIT || (event.type == VGLTF_EVENT_KEY_DOWN &&
                                           event.key.key == VGLTF_KEY_ESCAPE)) {
        goto out_main_loop;
      }
    }

    vgltf_engine_run_frame(&engine);
  }
out_main_loop:
  VGLTF_LOG_INFO("Exiting main loop");
  vgltf_engine_deinit(&engine);
  vgltf_platform_deinit(&platform);
  return 0;
deinit_platform:
  vgltf_platform_deinit(&platform);
err:
  return -1;
}
Go back to lisible.xyz