From 50eb947811580f901c60630fc606e966f9cd94c7 Mon Sep 17 00:00:00 2001 From: James Bulman Date: Fri, 3 Oct 2025 14:30:36 +0100 Subject: [PATCH] Initial commit Basic SDL3 window Build script for windows Added SDL3 submodule Added stb submodule --- .gitignore | 1 + .gitmodules | 6 +++++ code/first.c | 29 +++++++++++++++++++++++ thirdparty/SDL3 | 1 + thirdparty/stb | 1 + windows.bat | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 code/first.c create mode 160000 thirdparty/SDL3 create mode 160000 thirdparty/stb create mode 100644 windows.bat diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..018475e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "thirdparty/SDL3"] + path = thirdparty/SDL3 + url = https://github.com/libsdl-org/SDL +[submodule "thirdparty/stb"] + path = thirdparty/stb + url = https://github.com/nothings/stb diff --git a/code/first.c b/code/first.c new file mode 100644 index 0000000..6a6e98b --- /dev/null +++ b/code/first.c @@ -0,0 +1,29 @@ +#include +#include +#include + +int main(int argc, char **argv) { + if (!SDL_Init(SDL_INIT_VIDEO)) { + printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError()); + return 1; + } + + SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY); + if (!window) { + printf("[Error] :: Failed to create window (%s)\n", SDL_GetError()); + return 1; + } + + bool running = true; + while (running) { + SDL_Event e; + while (SDL_PollEvent(&e)) { + if (e.type == SDL_EVENT_QUIT) { running = false; } + } + } + + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} diff --git a/thirdparty/SDL3 b/thirdparty/SDL3 new file mode 160000 index 0000000..a8589a8 --- /dev/null +++ b/thirdparty/SDL3 @@ -0,0 +1 @@ +Subproject commit a8589a84226a6202831a3d49ff4edda4acab9acd diff --git a/thirdparty/stb b/thirdparty/stb new file mode 160000 index 0000000..fede005 --- /dev/null +++ b/thirdparty/stb @@ -0,0 +1 @@ +Subproject commit fede005abaf93d9d7f3a679d1999b2db341b360f diff --git a/windows.bat b/windows.bat new file mode 100644 index 0000000..143d28e --- /dev/null +++ b/windows.bat @@ -0,0 +1,62 @@ +@ECHO OFF +SETLOCAL + +PUSHD "%~dp0" > NUL + +IF NOT EXIST "build" ( MKDIR "build" ) + +PUSHD "build" + +SET deps=0 +SET release=0 + +FOR %%A in (%*) DO ( + SET %%A=1 +) + +IF NOT EXIST "deps\SDL3" ( + SET deps=1 +) + +IF %deps% equ 1 ( + ECHO [Building dependencies] + + RMDIR /Q /S "deps" + + RMDIR /Q /S "..\thirdparty\SDL3\build" 2> NUL + MKDIR "..\thirdparty\SDL3\build" + + PUSHD "..\thirdparty\SDL3\build" + + cmake -DCMAKE_INSTALL_PREFIX="..\..\..\build\deps\SDL3" .. + + IF %release% equ 1 ( + msbuild -p:Configuration=Release -p:Platform=x64 SDL3.sln + msbuild -p:Configuration=Release -p:Platform=x64 INSTALL.vcxproj + ) ELSE ( + msbuild -p:Configuration=Debug -p:Platform=x64 SDL3.sln + msbuild -p:Configuration=Debug -p:Platform=x64 INSTALL.vcxproj + ) + + POPD + + COPY "deps\SDL3\bin\SDL3.dll" "." + + MKDIR "deps\stb" + COPY "..\thirdparty\stb\*.h" "deps\stb" > NUL +) + +ECHO [Building source] + +SET COMPILER_OPTS=-nologo -W4 -I"deps\SDL3\include" -I"deps\stb" +SET LINKER_OPTS=-LIBPATH:"deps\SDL3\lib" SDL3.lib + +IF %release% equ 1 ( + ECHO [Release build] + cl -O2 -WX %COMPILER_OPTS% "..\code\first.c" -link %LINKER_OPTS% +) ELSE ( + ECHO [Debug build] + cl -Od -Zi %COMPILER_OPTS% "..\code\first.c" -link %LINKER_OPTS% +) + +POPD