From 496b9ca5d7c554bffcac4a759850011b3d42279a Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 24 Jun 2022 19:06:40 +0000 Subject: [PATCH] GLFW windows --- source/engine/log.h | 4 ++++ source/engine/window.c | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/source/engine/log.h b/source/engine/log.h index fcc707d..71a82af 100755 --- a/source/engine/log.h +++ b/source/engine/log.h @@ -9,6 +9,10 @@ #define LOG_CRITICAL 3 #define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__) +#define YughInfo(msg, ...) mYughLog(0, LOG_INFO, __LINE__, __FILE__, msg, __VA_ARGS__) +#define YughWarn(msg, ...) mYughLog(0, LOG_WARN, __LINE__, __FILE__, msg, __VA_ARGS__) +#define YughError(msg, ...) mYughLog(0, LOG_ERROR, __LINE__, __FILE__, msg, __VA_ARGS__) +#define YughCritical(msg, ...) mYughLog(0, LOG_CRITICAL, __LINE__, __FILE__, msg, __VA_ARGS__) void mYughLog(int category, int priority, int line, const char *file, const char *message, ...); diff --git a/source/engine/window.c b/source/engine/window.c index c8254d5..c7d4923 100755 --- a/source/engine/window.c +++ b/source/engine/window.c @@ -10,16 +10,24 @@ struct mSDLWindow *mainwin; -static struct mSDLWindow *windows[5]; +static struct mSDLWindow windows[5]; static int numWindows = 0; struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32_t flags) { - struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow)); + if (numWindows >= 5) { + YughError("Already max number of windows.", 5); + } + + struct mSDLWindow *w = &windows[numWindows++]; w->width = width; w->height = height; - w->window = glfwCreateWindow(width, height, name, NULL, NULL); + + if (numWindows > 0) + w->window = glfwCreateWindow(width, height, name, NULL, windows[0].window); + else + w->window = glfwCreateWindow(width, height, name, NULL, NULL); if (!w->window) { printf("Couldn't make GLFW window\n"); @@ -29,15 +37,11 @@ struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, glfwSwapInterval(1); - w->id = numWindows; - - - if (numWindows < 5) - windows[numWindows++] = w; + w->id = numWindows-1; } - mainwin = windows[0]; + mainwin = &windows[0]; return w; } @@ -132,7 +136,7 @@ void window_handle_event(struct mSDLWindow *w) void window_all_handle_events() { for (int i = 0; i < numWindows; i++) { - window_handle_event(windows[i]); + window_handle_event(&windows[i]); } }