first commit

This commit is contained in:
Matthew 2026-02-07 17:23:14 +11:00
commit ef612dcc19
6 changed files with 113 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build
include/SDL3

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "SDL"]
path = SDL
url = https://github.com/libsdl-org/SDL.git

5
.ignore Normal file
View File

@ -0,0 +1,5 @@
.git
.gitmodules
SDL
include/SDL3
build

1
SDL Submodule

@ -0,0 +1 @@
Subproject commit 3dc48a4890d37560e4159f50b7a6eadc9b9c1936

70
build.sh Executable file
View File

@ -0,0 +1,70 @@
#!/bin/bash
set -eu
for arg in "$@"; do declare $arg="1"; done
if [ ! -v release ]; then debug=1; fi
if [ ! -v clang ]; then gcc=1; fi
if [ -v release ]; then
build_mode="-g"
echo "[Release Mode]"
fi
if [ -v debug ];
build_mode="-O2"
then echo "[Debug Mode]"
fi
script_dir="$(dirname -- "${BASH_SOURCE[0]}" )"
cd $script_dir
mkdir -p build
mkdir -p include
# SDL
if ! [ -f "build/libSDL3.a" ]; then
cmake -S SDL -B SDL/build -DSDL_STATIC=ON -DSDL_SHARED=OFF
cd SDL/build
make
cd ../..
cp SDL/build/libSDL3.a build
cp -r SDL/include/SDL3 include
fi
if [ -v gcc ]; then
if ! [ -x "$(command -v g++)" ]; then
echo "Unable to find gcc compiler, try again with the clang flag or install gcc."
exit 1
fi
compiler_flags="-fzero-init-padding-bits=unions"
compiler="g++"
elif [ -v clang ]; then
if ! [ -x "$(command -v clang++)" ]; then
echo "Unable to find clang compiler, try again with the gcc flag or install clang"
exit 1
fi
compiler_flags=""
compiler="clang++"
fi
if [ -x "$(command -v mold)" ]; then
linker="mold";
elif [ -x "$(command -v lld)" ]; then
linker="lld";
elif [ -x "$(command -v ld)" ]; then
linker="ld"
else
echo "Unable to find a linker, please install mold, lld or ld"
exit 1
fi
src="main.cpp"
out="build/Renderer"
linker_flags="-lGL -Lbuild -l:libSDL3.a"
flags="-std=c++23 ${build_mode} ${compiler_flags} -Iinclude -fuse-ld=${linker} -o${out}"
$compiler $src $linker_flags $flags

32
main.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <cstdio>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
bool
Init()
{
const char* error = NULL;
SDL_SetAppMetadata("Renderer", "0.0", "com.sleepyday.renderer");
if(!SDL_Init(SDL_INIT_VIDEO))
{
error = SDL_GetError();
goto InitFailure;
}
return true;
InitFailure:
printf("Failed to initialize: [%s]", error);
return false;
}
int
main(int argc, char** argv)
{
Init();
}