diff options
| author | hachem <im@hachem.wtf> | 2026-08-25 04:08:12 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-25 04:08:12 +0200 |
| commit | 4be19ce68041b813c04f91cb39fed7e2a7bef2e6 (patch) | |
| tree | 5e42539e07508abe0e7e65b381592ca59dc74f54 /src | |
| parent | 5f6e1d8a85988de603c507c0f0663c5349ba61ee (diff) | |
feat: window seperation and run loop
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/application.c | 63 | ||||
| -rw-r--r-- | src/core/application.h | 24 | ||||
| -rw-r--r-- | src/main.c | 6 |
3 files changed, 91 insertions, 2 deletions
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 <stdlib.h> + +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 <GLFW/glfw3.h> + +#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*); @@ -1,6 +1,8 @@ -#include <stdio.h> +#include "core/application.h" int main(void) { - puts("type shi"); + struct Application* application = application_create(); + application_run(application); + application_destroy(application); } |
