summaryrefslogtreecommitdiff
path: root/gfx-app/include
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-app/include')
-rw-r--r--gfx-app/include/gfx/gfx_app.h95
1 files changed, 0 insertions, 95 deletions
diff --git a/gfx-app/include/gfx/gfx_app.h b/gfx-app/include/gfx/gfx_app.h
deleted file mode 100644
index ffff4bc..0000000
--- a/gfx-app/include/gfx/gfx_app.h
+++ /dev/null
@@ -1,95 +0,0 @@
1#pragma once
2
3#include <stdbool.h>
4
5typedef struct GfxAppState GfxAppState;
6
7/// Application settings.
8typedef struct GfxAppDesc {
9 int argc; // Number of application arguments.
10 const char** argv; // Application arguments.
11 int width; // Window width.
12 int height; // Window height.
13 int max_fps; // Desired maximum display framerate. 0 to disable.
14 double update_delta_time; // Desired delta time between frame updates.
15 const char* title; // Window title.
16 GfxAppState* app_state;
17} GfxAppDesc;
18
19typedef bool (*GfxAppInit)(GfxAppState*, int argc, const char** argv);
20typedef void (*GfxAppShutdown)(GfxAppState*);
21typedef void (*GfxAppUpdate)(GfxAppState*, double t, double dt);
22typedef void (*GfxAppRender)(GfxAppState*);
23typedef void (*GfxAppResize)(GfxAppState*, int width, int height);
24
25/// Application callback functions.
26typedef struct GfxAppCallbacks {
27 GfxAppInit init;
28 GfxAppShutdown shutdown;
29 GfxAppUpdate update;
30 GfxAppRender render;
31 GfxAppResize resize;
32} GfxAppCallbacks;
33
34typedef enum Key {
35 KeyA = 'a',
36 KeyB,
37 KeyC,
38 KeyD,
39 KeyE,
40 KeyF,
41 KeyG,
42 KeyH,
43 KeyI,
44 KeyJ,
45 KeyK,
46 KeyL,
47 KeyM,
48 KeyN,
49 KeyO,
50 KeyP,
51 KeyQ,
52 KeyR,
53 KeyS,
54 KeyT,
55 KeyU,
56 KeyV,
57 KeyW,
58 KeyX,
59 KeyY,
60 KeyZ,
61} Key;
62
63/// Create a window with an OpenGL context and run the main loop.
64bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*);
65
66/// Get the mouse coordinates relative to the app's window.
67void gfx_app_get_mouse_position(double* x, double* y);
68
69/// Return true if the given key is pressed.
70bool gfx_is_key_pressed(Key);
71
72/// Define a main function that initializes and puts the application in a loop.
73/// See also: gfx_app_run().
74#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, TITLE) \
75 int main(int argc, const char** argv) { \
76 GfxAppState app_state = {0}; \
77 gfx_app_run( \
78 &(GfxAppDesc){ \
79 .argc = argc, \
80 .argv = argv, \
81 .width = WIDTH, \
82 .height = HEIGHT, \
83 .max_fps = MAX_FPS, \
84 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, \
85 .title = TITLE, \
86 .app_state = &app_state, \
87 }, \
88 &(GfxAppCallbacks){ \
89 .init = (GfxAppInit)app_init, \
90 .update = (GfxAppUpdate)app_update, \
91 .render = (GfxAppRender)app_render, \
92 .resize = (GfxAppResize)app_resize, \
93 .shutdown = (GfxAppShutdown)app_end}); \
94 return 0; \
95 }