diff options
author | 3gg <3gg@shellblade.net> | 2023-01-03 08:49:54 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-01-03 08:49:54 -0800 |
commit | 1e3fcf5b38d67fb54102786be74af42be5c6792f (patch) | |
tree | 88bff4e24121c50d0e3c62f5ddb4eff6a3dfa238 /gltfview/src/main.c |
Initial commit.
Diffstat (limited to 'gltfview/src/main.c')
-rw-r--r-- | gltfview/src/main.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gltfview/src/main.c b/gltfview/src/main.c new file mode 100644 index 0000000..f7c372c --- /dev/null +++ b/gltfview/src/main.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include "game.h" | ||
2 | |||
3 | #include <gfx/gfx_app.h> | ||
4 | #include <log/log.h> | ||
5 | |||
6 | #include <stdlib.h> | ||
7 | |||
8 | static bool init(const GfxAppDesc* desc, void** app_state) { | ||
9 | Game* game = calloc(1, sizeof(Game)); | ||
10 | if (!game) { | ||
11 | LOGE("Failed to allocate game state"); | ||
12 | return false; | ||
13 | } | ||
14 | if (!game_new(game, desc->argc, desc->argv)) { | ||
15 | LOGE("Failed to initialize game\n"); | ||
16 | return false; | ||
17 | } | ||
18 | *app_state = game; | ||
19 | return true; | ||
20 | } | ||
21 | |||
22 | static void shutdown(void* app_state) { | ||
23 | assert(app_state); | ||
24 | Game* game = (Game*)(app_state); | ||
25 | game_end(game); | ||
26 | } | ||
27 | |||
28 | static void update(void* app_state, double t, double dt) { | ||
29 | assert(app_state); | ||
30 | Game* game = (Game*)(app_state); | ||
31 | game_update(game, t, dt); | ||
32 | } | ||
33 | |||
34 | static void render(void* app_state) { | ||
35 | assert(app_state); | ||
36 | Game* game = (Game*)(app_state); | ||
37 | game_render(game); | ||
38 | } | ||
39 | |||
40 | static void resize(void* app_state, int width, int height) { | ||
41 | assert(app_state); | ||
42 | Game* game = (Game*)(app_state); | ||
43 | game_set_viewport(game, width, height); | ||
44 | } | ||
45 | |||
46 | int main(int argc, const char** argv) { | ||
47 | const int initial_width = 1350; | ||
48 | const int initial_height = 900; | ||
49 | const int max_fps = 60; | ||
50 | |||
51 | gfx_app_run(&(GfxAppDesc){.argc = argc, | ||
52 | .argv = argv, | ||
53 | .width = initial_width, | ||
54 | .height = initial_height, | ||
55 | .max_fps = max_fps, | ||
56 | .update_delta_time = | ||
57 | max_fps > 0 ? 1.0 / (double)max_fps : 0.0}, | ||
58 | &(GfxAppCallbacks){.init = init, | ||
59 | .update = update, | ||
60 | .render = render, | ||
61 | .resize = resize, | ||
62 | .shutdown = shutdown}); | ||
63 | |||
64 | return 0; | ||
65 | } | ||