diff options
author | 3gg <3gg@shellblade.net> | 2023-06-24 18:46:13 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-06-24 18:46:13 -0700 |
commit | cf886f4fa406ddd48f30c00ad3c77f9dc134af3a (patch) | |
tree | abd916cf56b264a25257bcaade37caf1fbb974ac | |
parent | 9522580380393ae9d9b121f335579c5cfa5134f3 (diff) |
Add option to set window title. Add function to get mouse position.
-rw-r--r-- | gfx-app/include/gfx/gfx_app.h | 4 | ||||
-rw-r--r-- | gfx-app/src/gfx_app.c | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/gfx-app/include/gfx/gfx_app.h b/gfx-app/include/gfx/gfx_app.h index 4744992..0033bde 100644 --- a/gfx-app/include/gfx/gfx_app.h +++ b/gfx-app/include/gfx/gfx_app.h | |||
@@ -9,6 +9,7 @@ typedef struct GfxAppDesc { | |||
9 | int height; // Window height. | 9 | int height; // Window height. |
10 | int max_fps; // Desired maximum display framerate. 0 to disable. | 10 | int max_fps; // Desired maximum display framerate. 0 to disable. |
11 | double update_delta_time; // Desired delta time between frame updates. | 11 | double update_delta_time; // Desired delta time between frame updates. |
12 | const char* title; // Window title. | ||
12 | } GfxAppDesc; | 13 | } GfxAppDesc; |
13 | 14 | ||
14 | typedef struct GfxAppCallbacks { | 15 | typedef struct GfxAppCallbacks { |
@@ -21,3 +22,6 @@ typedef struct GfxAppCallbacks { | |||
21 | 22 | ||
22 | /// Create a window with an OpenGL context and run the main loop. | 23 | /// Create a window with an OpenGL context and run the main loop. |
23 | bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*); | 24 | bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*); |
25 | |||
26 | /// Get the mouse coordinates relative to the app's window. | ||
27 | void gfx_app_get_mouse_position(double* x, double* y); | ||
diff --git a/gfx-app/src/gfx_app.c b/gfx-app/src/gfx_app.c index 31f8448..2d54e3d 100644 --- a/gfx-app/src/gfx_app.c +++ b/gfx-app/src/gfx_app.c | |||
@@ -95,8 +95,10 @@ bool gfx_app_run(const GfxAppDesc* desc, const GfxAppCallbacks* callbacks) { | |||
95 | // TODO: Test antialiasing later on. | 95 | // TODO: Test antialiasing later on. |
96 | // glfwWindowHint(GLFW_SAMPLES, 4); | 96 | // glfwWindowHint(GLFW_SAMPLES, 4); |
97 | 97 | ||
98 | g_gfx_app.window = glfwCreateWindow( | 98 | const char* title = desc->title ? desc->title : "Gfx Application"; |
99 | desc->width, desc->height, "Gfx Application", NULL, NULL); | 99 | |
100 | g_gfx_app.window = | ||
101 | glfwCreateWindow(desc->width, desc->height, title, NULL, NULL); | ||
100 | if (!g_gfx_app.window) { | 102 | if (!g_gfx_app.window) { |
101 | LOGE("glfwCreateWindow() failed"); | 103 | LOGE("glfwCreateWindow() failed"); |
102 | goto cleanup; | 104 | goto cleanup; |
@@ -128,3 +130,7 @@ cleanup: | |||
128 | glfwTerminate(); | 130 | glfwTerminate(); |
129 | return success; | 131 | return success; |
130 | } | 132 | } |
133 | |||
134 | void gfx_app_get_mouse_position(double* x, double* y) { | ||
135 | glfwGetCursorPos(g_gfx_app.window, x, y); | ||
136 | } | ||