From 4be19ce68041b813c04f91cb39fed7e2a7bef2e6 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 25 Aug 2026 04:08:12 +0200 Subject: feat: window seperation and run loop --- src/core/application.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/application.h | 24 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/core/application.c create mode 100644 src/core/application.h (limited to 'src/core') diff --git a/src/core/application.c b/src/core/application.c new file mode 100644 index 0000000..f859434 --- /dev/null +++ b/src/core/application.c @@ -0,0 +1,63 @@ +#include "application.h" + +#include + +struct Application* application_create(void) +{ + // legit who gives a fuck about validation bro + glfwInit(); + + struct Application* application = (struct Application*) malloc(sizeof(struct Application)); + + application->game_window = glfwCreateWindow(GAME_WINDOW_WIDTH, GAME_WINDOW_HEIGHT, + "I can't see or hear shit", NULL, NULL); + application->debug_window = glfwCreateWindow(DEBUG_WINDOW_WIDTH, DEBUG_WINDOW_HEIGHT, + "Debug", NULL, application->game_window); + + return application; +} + +void application_render_game(struct Application* application) +{ + glfwMakeContextCurrent(application->game_window); + + glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(application->game_window); +} + +void application_render_debug(struct Application* application) +{ + glfwMakeContextCurrent(application->debug_window); + + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(application->debug_window); +} + +void application_update(struct Application* application) +{ + glfwPollEvents(); +} + +void application_run(struct Application* application) +{ + while (!glfwWindowShouldClose(application->game_window) && + !glfwWindowShouldClose(application->debug_window)) + { + application_render_game(application); + application_render_debug(application); + application_update(application); + } +} + +void application_destroy(struct Application* application) +{ + glfwDestroyWindow(application->game_window); + glfwDestroyWindow(application->debug_window); + glfwTerminate(); + + free(application); +} diff --git a/src/core/application.h b/src/core/application.h new file mode 100644 index 0000000..4a2bc5c --- /dev/null +++ b/src/core/application.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#define GAME_WINDOW_WIDTH 1920 +#define GAME_WINDOW_HEIGHT 1080 + +#define DEBUG_WINDOW_WIDTH 800 +#define DEBUG_WINDOW_HEIGHT 800 + +struct Application +{ + struct GLFWwindow* game_window; + struct GLFWwindow* debug_window; +}; + +struct Application* application_create(void); + +void application_render_game(struct Application*); +void application_render_debug(struct Application*); +void application_update(struct Application*); +void application_run(struct Application*); + +void application_destroy(struct Application*); -- cgit v1.3