hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-25 04:08:12 +0200
committerhachem <im@hachem.wtf>2026-08-25 04:08:12 +0200
commit4be19ce68041b813c04f91cb39fed7e2a7bef2e6 (patch)
tree5e42539e07508abe0e7e65b381592ca59dc74f54
parent5f6e1d8a85988de603c507c0f0663c5349ba61ee (diff)
feat: window seperation and run loop
-rw-r--r--.gitmodules3
m---------ext/glfw0
-rw-r--r--premake5.lua186
-rw-r--r--src/core/application.c63
-rw-r--r--src/core/application.h24
-rw-r--r--src/main.c6
6 files changed, 274 insertions, 8 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..729155b
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "ext/glfw"]
+ path = ext/glfw
+ url = https://github.com/glfw/glfw.git
diff --git a/ext/glfw b/ext/glfw
new file mode 160000
+Subproject 92dcf4ce74f2e2554a98fea09be7c705c17daa5
diff --git a/premake5.lua b/premake5.lua
index 79c1165..a464f28 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -1,3 +1,17 @@
+-- premake5's built-in `clean` action is unported ("has not yet been ported"),
+-- so provide our own: wipe the build output and the generated project files.
+newaction {
+ trigger = "clean",
+ description = "Remove build output (bin, bin-int) and generated project files",
+ execute = function()
+ os.rmdir("bin")
+ os.rmdir("bin-int")
+ os.remove("Makefile")
+ for _, f in ipairs(os.matchfiles("*.make")) do os.remove(f) end
+ print("Cleaned: bin/, bin-int/, Makefile, *.make")
+ end
+}
+
workspace "icsohs"
architecture "x64"
startproject "icsohs"
@@ -18,7 +32,146 @@ workspace "icsohs"
defines "ICSOHS_MACOS"
architecture "ARM64"
-local outputdir = "%{cfg.buildcfg}-%{cfg.system}/%{prj.name}"
+outputdir = "%{cfg.buildcfg}-%{cfg.system}/%{prj.name}"
+includedir = {}
+includedir["glfw"] = "ext/glfw/include"
+
+group "dependencies"
+project "GLFW"
+ kind "StaticLib"
+ language "C"
+ staticruntime "on"
+ warnings "off"
+
+ targetdir ("bin/" .. outputdir)
+ objdir ("bin-int/" .. outputdir)
+
+ files
+ {
+ "ext/glfw/src/context.c",
+ "ext/glfw/src/init.c",
+ "ext/glfw/src/input.c",
+ "ext/glfw/src/monitor.c",
+ "ext/glfw/src/platform.c",
+ "ext/glfw/src/vulkan.c",
+ "ext/glfw/src/window.c",
+
+ "ext/glfw/src/internal.h",
+ "ext/glfw/src/platform.h",
+ "ext/glfw/src/mappings.h",
+
+ "ext/glfw/src/null_init.c",
+ "ext/glfw/src/null_joystick.c",
+ "ext/glfw/src/null_joystick.h",
+ "ext/glfw/src/null_monitor.c",
+ "ext/glfw/src/null_platform.h",
+ "ext/glfw/src/null_window.c",
+ }
+
+ filter "system:linux"
+ pic "On"
+ systemversion "latest"
+
+ files
+ {
+ "ext/glfw/src/x11_init.c",
+ "ext/glfw/src/x11_monitor.c",
+ "ext/glfw/src/x11_platform.h",
+ "ext/glfw/src/x11_window.c",
+ "ext/glfw/src/xkb_unicode.c",
+ "ext/glfw/src/xkb_unicode.h",
+
+ "ext/glfw/src/wl_init.c",
+ "ext/glfw/src/wl_monitor.c",
+ "ext/glfw/src/wl_platform.h",
+ "ext/glfw/src/wl_window.c",
+
+ "ext/glfw/src/posix_module.c",
+ "ext/glfw/src/posix_time.c",
+ "ext/glfw/src/posix_time.h",
+ "ext/glfw/src/posix_thread.c",
+ "ext/glfw/src/posix_thread.h",
+
+ "ext/glfw/src/glx_context.c",
+ "ext/glfw/src/egl_context.c",
+ "ext/glfw/src/osmesa_context.c",
+
+ "ext/glfw/src/linux_joystick.c",
+ "ext/glfw/src/linux_joystick.h"
+ }
+
+ defines
+ {
+ "_GLFW_X11"
+ }
+
+ filter "system:macosx"
+ pic "On"
+
+ files
+ {
+ "ext/glfw/src/cocoa_init.m",
+ "ext/glfw/src/cocoa_joystick.h",
+ "ext/glfw/src/cocoa_joystick.m",
+ "ext/glfw/src/cocoa_monitor.m",
+ "ext/glfw/src/cocoa_platform.h",
+ "ext/glfw/src/macos_time.c",
+ "ext/glfw/src/macos_time.h",
+ "ext/glfw/src/cocoa_window.m",
+
+ "ext/glfw/src/nsgl_context.m",
+ "ext/glfw/src/egl_context.c",
+ "ext/glfw/src/osmesa_context.c",
+
+ "ext/glfw/src/posix_module.c",
+ "ext/glfw/src/posix_thread.c",
+ "ext/glfw/src/posix_thread.h"
+ }
+
+ defines
+ {
+ "_GLFW_COCOA"
+ }
+
+ filter "system:windows"
+ systemversion "latest"
+
+ files
+ {
+ "ext/glfw/src/win32_init.c",
+ "ext/glfw/src/win32_joystick.c",
+ "ext/glfw/src/win32_joystick.h",
+ "ext/glfw/src/win32_module.c",
+ "ext/glfw/src/win32_monitor.c",
+ "ext/glfw/src/win32_platform.h",
+ "ext/glfw/src/win32_thread.c",
+ "ext/glfw/src/win32_thread.h",
+ "ext/glfw/src/win32_time.c",
+ "ext/glfw/src/win32_time.h",
+ "ext/glfw/src/win32_window.c",
+ "ext/glfw/src/wgl_context.c",
+ "ext/glfw/src/egl_context.c",
+ "ext/glfw/src/osmesa_context.c"
+ }
+
+ defines
+ {
+ "_GLFW_WIN32",
+ "_CRT_SECURE_NO_WARNINGS",
+ }
+
+ filter "configurations:debug"
+ runtime "Debug"
+ symbols "on"
+ filter "configurations:release"
+ runtime "Release"
+ optimize "speed"
+ filter "configurations:dist"
+ runtime "Release"
+ optimize "speed"
+ symbols "off"
+group ""
+
project "icsohs"
kind "ConsoleApp"
@@ -29,10 +182,8 @@ project "icsohs"
targetdir ("bin/" .. outputdir)
objdir ("bin-int/" .. outputdir)
- defines
- {
- "_CRT_SECURE_NO_WARNINGS",
- }
+ includedirs "src"
+ defines "_CRT_SECURE_NO_WARNINGS"
files
{
@@ -40,10 +191,33 @@ project "icsohs"
"src/**.c",
}
- includedirs "src"
+ links
+ {
+ "GLFW"
+ }
+
+ externalincludedirs
+ {
+ "%{includedir.glfw}"
+ }
filter "system:windows"
systemversion "latest"
+ filter "system:macosx"
+ defines
+ {
+ "_GLFW_COCOA",
+ "GL_SILENCE_DEPRECATION"
+ }
+ links
+ {
+ "Cocoa.framework",
+ "IOKit.framework",
+ "CoreFoundation.framework",
+ "CoreVideo.framework",
+ "OpenGL.framework",
+ "QuartzCore.framework",
+ }
filter "configurations:debug"
defines "ICSOHS_DEBUG"
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*);
diff --git a/src/main.c b/src/main.c
index 902e18a..9a2179b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}