summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-10-31 23:55:42 +0000
committeronelin <oscar@nelin.dk>2025-11-02 22:07:17 +0000
commitd38deeef3af2316a666f8fc0173940bd769b748e (patch)
tree6e30d4a9eea18daa5705c894f28cd99ff047e8f9 /src/window.c
parent6c077751982ea2c7bd2d9262b01b9f8602f80dc8 (diff)
Flatten project structure
This will make it easier to break up the code into smaller chunks again later. One would think doing this seems fun to me at this point.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c
new file mode 100644
index 0000000..ea42678
--- /dev/null
+++ b/src/window.c
@@ -0,0 +1,82 @@
+#include <time.h>
+
+/* TODO: REMOVE THIS INCLUSION */
+#include <daw/daw.h>
+
+#include <daw/types.h>
+#include <daw/logging.h>
+
+#define ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS
+#include <daw/window.h>
+#undef ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS
+
+#include <glad/gl.h>
+
+#undef GLFW_INCLUDE_NONE
+#include <GLFW/glfw3.h>
+
+#include <cglm/ivec2.h>
+
+extern Instance* GLOBAL_PLATFORM;
+
+static inline u64 platform_get_time_usec(void) {
+ struct timespec t;
+ int res = clock_gettime(CLOCK_MONOTONIC, &t);
+ if (res != 0) {
+ // TODO: Check errno
+ WARN("Failed to get system time");
+ }
+ return (u64)(t.tv_sec * 1000000 + t.tv_nsec / 1000);
+}
+
+/* wrapper to get time in ms */
+u64 (*get_time)(void) = platform_get_time_usec;
+
+
+#define DAW_WINDOW_VSYNC (1 << 0)
+#define DAW_WINDOW_FULLSCREEN (1 << 1)
+#define DAW_WINDOW_RESIZEABLE (1 << 2)
+
+// Wrapper to get a specific window and set up related structures.
+// What the fuck is this doing here.
+Window* Window_new(const struct Platform* p, const char *restrict title, Window_framework framework, Window_renderer renderer, ivec2 size, u32 flags) {
+ Window* w = NULL;
+
+ switch (framework) {
+ case WINDOW_FRAMEWORK_GLFW:
+ switch (renderer) {
+ case WINDOW_RENDERER_OPENGL:
+ /* For now, pass instance as NULL, fix it once all the necessary bs is
+ * out of struct Instance */
+ w = p->window_init(title, size, flags);
+
+ w->bindings = NULL;
+ w->bindings_sz = 0;
+ w->bindings_len = 0;
+
+ /// TODO
+ //w->cam = &default_camera;
+ return w;
+ break;
+ default:
+ ERROR("Unsupported renderer.");
+ }
+ break;
+ default:
+ ERROR("Unsupported framework.");
+ }
+ return NULL;
+}
+
+void get_mousepos(double *x, double *y) {
+ Window* w = GLOBAL_PLATFORM->window;
+
+ switch(w->framework) {
+ case WINDOW_FRAMEWORK_GLFW:
+ glfwGetCursorPos(GLOBAL_PLATFORM->window->window, x, y);
+ break;
+ default:
+ ERROR("get_mouse_pos not implemented for chosen framework.");
+ }
+
+}