From cf886f4fa406ddd48f30c00ad3c77f9dc134af3a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 24 Jun 2023 18:46:13 -0700 Subject: Add option to set window title. Add function to get mouse position. --- gfx-app/include/gfx/gfx_app.h | 4 ++++ 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 { int height; // Window height. int max_fps; // Desired maximum display framerate. 0 to disable. double update_delta_time; // Desired delta time between frame updates. + const char* title; // Window title. } GfxAppDesc; typedef struct GfxAppCallbacks { @@ -21,3 +22,6 @@ typedef struct GfxAppCallbacks { /// Create a window with an OpenGL context and run the main loop. bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*); + +/// Get the mouse coordinates relative to the app's window. +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) { // TODO: Test antialiasing later on. // glfwWindowHint(GLFW_SAMPLES, 4); - g_gfx_app.window = glfwCreateWindow( - desc->width, desc->height, "Gfx Application", NULL, NULL); + const char* title = desc->title ? desc->title : "Gfx Application"; + + g_gfx_app.window = + glfwCreateWindow(desc->width, desc->height, title, NULL, NULL); if (!g_gfx_app.window) { LOGE("glfwCreateWindow() failed"); goto cleanup; @@ -128,3 +130,7 @@ cleanup: glfwTerminate(); return success; } + +void gfx_app_get_mouse_position(double* x, double* y) { + glfwGetCursorPos(g_gfx_app.window, x, y); +} -- cgit v1.2.3