62 Commits
master ... dev

Author SHA1 Message Date
f75a438422 obj renders 2026-02-23 16:53:57 -06:00
7a2131fc93 text appears 2026-02-23 12:50:16 -06:00
a5c21ea30d work on text 2026-02-22 22:48:26 -06:00
ce43c56ea6 render from json 2026-02-19 22:41:46 -06:00
74c980adb0 render obj file 2026-02-19 07:54:54 -06:00
fec99fc737 render obj file 2026-02-18 23:07:53 -06:00
da1292d9e5 work on object system 2026-02-17 14:09:20 -06:00
e9f1f49416 add JObject 2026-02-16 22:41:42 -06:00
fda88a906b add draw types 2026-02-16 22:41:20 -06:00
5fd5eb892b add nvim devShells 2026-02-16 12:39:33 -06:00
6abcaeb0d1 add zsh devShell 2026-02-16 12:30:25 -06:00
a422e5cfa2 use perspective projection 2026-02-16 12:28:13 -06:00
c25ed1949d add SandboxEmbed 2026-02-15 23:56:24 -06:00
2899932f7f fix TerminalEmbed 2026-02-15 16:07:21 -06:00
0ab0f4af47 fix 2026-02-14 17:44:30 -06:00
d6f8036175 flake parts 2026-02-14 17:08:36 -06:00
f01bd49fb1 flake parts 2026-02-14 16:24:35 -06:00
874de65dba flake parts 2026-02-14 13:12:52 -06:00
f9f311c82b sandbox 2026-02-13 08:24:03 -06:00
ec8a9c9f4f triangle and imgui 2026-02-11 08:15:55 -06:00
6c33eada03 triangle 2026-02-11 00:03:05 -06:00
badb3c4ec8 triangle 2026-02-10 23:53:52 -06:00
0244f463c4 triangle? 2026-02-10 23:51:27 -06:00
1f22a661cd the great typo of 2026 2026-02-10 18:21:18 -06:00
80d64f5114 test triangle 2026-02-10 15:40:25 -06:00
3c593edeca test triangle 2026-02-10 14:43:43 -06:00
263f0201ca test triangle 2026-02-10 14:39:45 -06:00
65e15ecfa4 test triangle 2026-02-10 14:35:54 -06:00
7d777c9578 work on renderer 2026-02-10 13:52:56 -06:00
874a8a1115 work on renderer 2026-02-10 13:50:44 -06:00
e4d84686c4 work on renderer 2026-02-10 13:41:49 -06:00
914de55f85 work on renderer 2026-02-10 13:40:44 -06:00
6dba251457 work on renderer 2026-02-10 13:39:42 -06:00
dd1befc2a0 work on renderer 2026-02-10 13:37:49 -06:00
086e5f5126 work on renderer 2026-02-08 17:29:56 -06:00
f277dee1f7 polymorphic windows 2026-02-08 11:57:18 -06:00
bad4bd70bc folders 2026-02-08 00:32:46 -06:00
b97957ec53 use extratools 2026-02-07 12:49:47 -06:00
bedd7a5dfd prepare for audio implimentations 2026-02-07 12:45:55 -06:00
89ea39ee60 add extratools.h 2026-02-07 12:44:07 -06:00
e7544e1cc1 add extratools.h 2026-02-07 12:43:10 -06:00
98f990cb57 add concepts 2026-02-07 11:54:47 -06:00
9b0be39b91 start template refactor 2026-02-07 11:47:06 -06:00
9a89ab3bbc start template refactor 2026-02-07 11:45:43 -06:00
8b0192c9b8 Sketchy Multi Viewports 2026-02-05 23:59:11 -06:00
8581589bfe TestTriangle works 2026-02-04 17:31:17 -06:00
9dfabc6dae TestTriangle works 2026-02-04 15:42:30 -06:00
3f102638b0 work on TestTriangle 2026-02-04 14:37:06 -06:00
5ab345460c TestTriangle 2026-02-04 09:29:15 -06:00
e67df40233 TestTriangle 2026-02-04 09:04:44 -06:00
07b4518cb4 TestTriangle 2026-02-04 08:41:09 -06:00
43d950b035 add triangle test 2026-02-04 08:35:16 -06:00
78a8c9bf95 return to something that works 2026-02-04 00:30:52 -06:00
7a45547ad9 attempt multi-viewports 2026-02-03 21:21:27 -06:00
21080c5c63 debating submodules 2026-02-03 21:17:12 -06:00
68524696df spellcheck 2026-02-03 20:15:15 -06:00
8c0cba9397 ccls 2026-02-03 20:13:10 -06:00
afe6254317 ccls? 2026-02-03 20:04:07 -06:00
e38a83e521 ccls? 2026-02-03 20:01:32 -06:00
7517ee8593 scope 2026-02-03 18:16:37 -06:00
148ed1253c try dev shell 2026-02-03 18:15:37 -06:00
cd19db0b88 flakes shouldn't be executable 2026-02-03 14:35:38 -06:00
111 changed files with 3976 additions and 1280 deletions

10
.ccls Normal file
View File

@@ -0,0 +1,10 @@
clang++
-Isrc/include
-Isrc
-Ivendor/imgui
-Ivendor/notcurses/include
-Ivendor/GameNetworkingSockets/include
-DWINDOW_GLFW
-DWINDOW_SDL3
-DRENDERER_OPENGL
-DRENDERER_SDL3

5
.gitignore vendored
View File

@@ -1 +1,4 @@
vendor/*
vendor/
.ccls-cache/
imgui.ini
result*

View File

@@ -1,121 +0,0 @@
{ inputs, pkgs, ... }: {
MinimalApp = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
outputs = [ "out" "dev" ];
nativeBuildInputs = with pkgs; [
clang
];
/*buildInputs = with pkgs; [
];*/
buildPhase = ''
clang++ \
src/example_apps/MinimalApp/MinimalApp.cpp \
-I src -I include \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
mkdir -p $dev/include/modules
cp -r include/* $dev/include
cp -r modules $dev/include/modules
'';
};
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
src/example_apps/ImguiEmbed/*.cpp \
modules/Archimedes-Modules/TestImgui/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TerminalEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
src/example_apps/TerminalEmbed/*.cpp \
modules/Archimedes-Modules/Terminal/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
}

View File

@@ -1,513 +0,0 @@
{ inputs, pkgs, ... }: {
TestMenu = pkgs.stdenvNoCC.mkDerivation {
name = "TestMenu";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestMenu/*.cpp \
-fpic -shared \
-Wall \
-DTESTMENU_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestNotCurses = pkgs.stdenvNoCC.mkDerivation {
name = "TestNotCurses";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
notcurses
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestNotCurses/*.cpp \
-fpic -shared \
-I include \
-Wall \
-lnotcurses \
-DTESTNOTCURSES_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
Print = pkgs.stdenvNoCC.mkDerivation {
name = "Print";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Print/*.cpp \
-fpic -shared \
-I include \
-Wall \
-DPRINT_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
DependsOnPrint = pkgs.stdenvNoCC.mkDerivation {
name = "DependsOnPrint";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/DependsOnPrint/*.cpp \
-fpic -shared \
-I include \
-Wall \
-DDEPENDSONPRINT_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
DependsOnPrintStatic = pkgs.stdenvNoCC.mkDerivation {
name = "DependsOnPrintStatic";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/DependsOnPrintStatic/*.cpp \
modules/Archimedes-Modules/Print/*.cpp \
-fpic -shared \
-I include -I . \
-DDEPENDSONPRINTSTATIC_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestImgui = pkgs.stdenvNoCC.mkDerivation {
name = "TestImgui";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestImgui/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DTESTIMGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
Calculator = pkgs.stdenvNoCC.mkDerivation {
name = "Calculator";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Calculator/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DCALCULATOR_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestClay = pkgs.stdenvNoCC.mkDerivation {
name = "TestClay";
src = ./.;
clay = inputs.clay;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestClay/*.cpp \
-fpic -shared \
-I include \
-DRENDERER=1 \
-DWINDOW=1 \
-DTESTCLAY_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ChatServer = pkgs.stdenvNoCC.mkDerivation {
name = "ChatServer";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
modules/ServerModule/*.cpp \
-fpic -shared \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-I include -I . \
-lGameNetworkingSockets \
-DCHATSERVER_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ChatServerVoice = pkgs.stdenvNoCC.mkDerivation {
name = "ChatServerVoice";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/ChatVoice/ChatServerVoice/*.cpp \
modules/ServerModule/*.cpp \
-fpic -shared \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-I include -I . \
-lGameNetworkingSockets \
-DCHATSERVERVOICE_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ChatClient = pkgs.stdenvNoCC.mkDerivation {
name = "ChatClient";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
modules/ClientModule/*.cpp \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCHATCLIENT_DYNAMIC \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ChatClientVoice = pkgs.stdenvNoCC.mkDerivation {
name = "ChatClientVoice";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
sdl3
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/ChatVoice/ChatClientVoice/*.cpp \
modules/ClientModule/*.cpp \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCHATCLIENTVOICE_DYNAMIC \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_sdl3.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=2 \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lSDL3 -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
Terminal = pkgs.stdenvNoCC.mkDerivation {
name = "Terminal";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Terminal/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DTERMINAL_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
Ollama = pkgs.stdenvNoCC.mkDerivation {
name = "Ollama";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
curl
nlohmann_json
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Ollama/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DOLLAMA_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
}

17
dev/overlays.nix Normal file
View File

@@ -0,0 +1,17 @@
{ self, inputs, ... }: {
flake.overlays.glfw-old = (final: prev: let
pkgs-old = import inputs.nixpkgs-old { system = prev.stdenv.hostPlatform.system; };
in { glfw = pkgs-old.glfw; });
perSystem = { lib, system, pkgs, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
self.overlays.glfw-old
];
config = {};
};
};
}

110
dev/shells.nix Normal file
View File

@@ -0,0 +1,110 @@
{ ... }: {
perSystem = { config, system, pkgs, self', inputs', ... }: {
devShells = {
bash = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
'';
};
nvim-bash = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
exec nvim
'';
};
zsh = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
export SHELL=$(realpath `which zsh`)
exec zsh
'';
};
nvim-zsh = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
export SHELL=$(realpath `which zsh`)
exec nvim
'';
};
default = self'.devShells.bash;
};
};
}

6
dev/systems.nix Normal file
View File

@@ -0,0 +1,6 @@
{ ... }: {
systems = [
"x86_64-linux"
];
}

81
flake.lock generated Executable file → Normal file
View File

@@ -16,14 +16,32 @@
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1769996383,
"narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "57928607ea566b5db3ad13af0e57e921e6b12381",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"imgui": {
"flake": false,
"locked": {
"lastModified": 1769795052,
"narHash": "sha256-JRA4E/aFcEEoB9FYHcLcEs4tgcX41ix2VjMV61PVQeA=",
"lastModified": 1770923283,
"narHash": "sha256-EOhlmnhoJRNjU7o7aCXnRrOw7JM0nq0VWDVnUJ6A6Xo=",
"owner": "ocornut",
"repo": "imgui",
"rev": "913a3c60561bb07e8fd410ec7d4a8f6f485defd6",
"rev": "3fb22b836ba968c62d280d9de079ec5ed7fcd1b5",
"type": "github"
},
"original": {
@@ -33,13 +51,28 @@
"type": "github"
}
},
"import-tree": {
"locked": {
"lastModified": 1771045967,
"narHash": "sha256-oYO4poyw0Sb/db2PigqugMlDwsvwLg6CSpFrMUWxA3Q=",
"owner": "vic",
"repo": "import-tree",
"rev": "c968d3b54d12cf5d9c13f16f7c545a06c9d1fde6",
"type": "github"
},
"original": {
"owner": "vic",
"repo": "import-tree",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1769900590,
"narHash": "sha256-I7Lmgj3owOTBGuauy9FL6qdpeK2umDoe07lM4V+PnyA=",
"lastModified": 1770770419,
"narHash": "sha256-iKZMkr6Cm9JzWlRYW/VPoL0A9jVKtZYiU4zSrVeetIs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "41e216c0ca66c83b12ab7a98cc326b5db01db646",
"rev": "6c5e707c6b5339359a9a9e215c5e66d6d802fd7a",
"type": "github"
},
"original": {
@@ -49,11 +82,45 @@
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1769909678,
"narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "72716169fe93074c333e8d0173151350670b824c",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs-old": {
"locked": {
"lastModified": 1720535198,
"narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"clay": "clay",
"flake-parts": "flake-parts",
"imgui": "imgui",
"nixpkgs": "nixpkgs"
"import-tree": "import-tree",
"nixpkgs": "nixpkgs",
"nixpkgs-old": "nixpkgs-old"
}
}
},

260
flake.nix Executable file → Normal file
View File

@@ -3,6 +3,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
nixpkgs-old.url = "github:nixos/nixpkgs/nixos-23.11"; # Until Dear ImGUI has multi viewports on wayland
imgui = {
url = "github:ocornut/imgui?ref=docking";
flake = false;
@@ -11,258 +12,17 @@
url = "github:nicbarker/clay";
flake = false;
};
flake-parts.url = "github:hercules-ci/flake-parts";
import-tree.url = "github:vic/import-tree";
};
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in {
Archimedes = {
examples = import ./ExampleApps.nix { inherit inputs; inherit pkgs; };
outputs = { self, flake-parts, import-tree, ... } @ inputs:
flake-parts.lib.mkFlake {
inputs = inputs // {
src = ./src;
};
} (import-tree [ ./src ./dev ]);
Modules = {
examples = import ./ExampleModules.nix { inherit inputs; inherit pkgs; };
ServerModule = pkgs.stdenvNoCC.mkDerivation {
name = "ServerModule";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/ServerModule/*.cpp \
-fpic -shared \
-I include \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DSERVERMODULE_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ClientModule = pkgs.stdenvNoCC.mkDerivation {
name = "ClientModule";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/ClientModule/*.cpp \
-fpic -shared \
-I include \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCLIENTMODULE_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
WindowModule = pkgs.stdenvNoCC.mkDerivation {
name = "WindowModule";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/WindowModule/*.cpp \
-fpic -shared \
-I include \
-DRENDERER=1 \
-DWINDOW=1 \
-DWINDOWMODULE_DYNAMIC \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ImguiModule = pkgs.stdenvNoCC.mkDerivation {
name = "ImguiModule";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DIMGUIMODULE_DYNAMIC \
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
MainGUIsdl = pkgs.stdenvNoCC.mkDerivation {
name = "MainGUI";
src = ./.;
inherit imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
sdl3
];
buildPhase = ''
clang++ \
modules/MainGUI/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_sdl3.cpp \
$imgui/backends/imgui_impl_sdlrenderer3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=2 \
-DWINDOW=2 \
-DMAINGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lSDL3 \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
MainGUI = pkgs.stdenvNoCC.mkDerivation {
name = "MainGUI";
src = ./.;
inherit imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/MainGUI/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DMAINGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
packages.${system}.default = self.Archimedes.examples.MinimalApp;
apps.${system}.default = {
type = "app";
program = "${self.Archimedes.examples.MinimalApp}/bin/Archimedes";
};
};
}

View File

@@ -1,34 +0,0 @@
#ifndef RENDERER_H
#define RENDERER_H
#include "pch.hpp"
#include "RendererOpenGL/RendererOpenGL.h"
#include "RendererSDL3/RendererSDL3.h"
namespace Archimedes {
class Renderer {
public:
int w, h;
~Renderer() {}
bool init(void* ptr) { return r.init(ptr); }
void render() {
r.render(rc, w, h);
}
std::list<std::function<void()>>& getCmdList() {
return rc;
}
RendererImpl& getRendererImpl() { return r; }
private:
std::list<std::function<void()>> rc;
RendererImpl r;
};
}
#endif

View File

@@ -1,44 +0,0 @@
#if RENDERER == 1
#ifndef RENDERER_OPENGL
#define RENDERER_OPENGL
#include "pch.hpp"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
class RendererOpenGL {
public:
typedef void renderCmd();
RendererOpenGL() {};
~RendererOpenGL() {};
bool init(void* p) {
return glewInit() == GLEW_OK;
};
void render(std::list<std::function<void()>> cmdList, int& w, int& h) {
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT);
for(auto f : cmdList)
f();
}
};
typedef RendererOpenGL RendererImpl;
}
#endif
#endif

View File

@@ -1,47 +0,0 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "WindowEvents.h"
#include "utils/Renderer/Renderer.h"
#include "WindowGLFW/WindowGLFW.h"
#include "WindowSDL3/WindowSDL3.h"
namespace Archimedes {
class Window {
public:
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {}
~Window() {}
bool shouldClose() { return window.shouldClose(); }
void getSize(int& w, int& h) {
window.getSize(w, h);
}
void doFrame() {
renderer->render();
window.doFrame();
window.pollEvents();
}
Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) { renderer = r; }
WindowImpl& getWindowImpl() { return window; }
private:
Renderer* renderer;
WindowImpl window;
};
}
#endif

View File

@@ -1,121 +0,0 @@
#include "ImguiModule.h"
#include "pch.hpp"
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
name = "ImguiModule";
WindowModule* wm = new WindowModule(a, h);
deps[*wm] = wm;
}
ImguiModule::~ImguiModule() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
wm->getRenderer()->getCmdList().erase(rcmd_it);
#if WINDOW == 2
wm->removeEventFn(ecmd_it);
#endif
rendererShutdown();
windowShutdown();
ImGui::DestroyContext();
wm->releaseWindow(window);
}
}
void ImguiModule::onLoad() {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
if(!wm) {
std::cout << "No WindowModule for ImguiModule!\n";
std::abort();
}
window = wm->aquireWindow();
#if RENDERER == 2
renderer = window->getRenderer()->getRendererImpl().renderer;
#endif
IMGUI_CHECKVERSION();
context = ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
#ifdef CUSTOMFONT
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
#endif
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
if(!windowInit())
std::cout << "windowInit failed\n";
if(!rendererInit()) {
std::cout << "rendererInit failed!\n" << std::endl;
}
wm->getRenderer()->getCmdList().push_back([this](){
ImGui::Render();
rendererRenderDrawData();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
});
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
#if WINDOW == 2
ecmd_it = wm->addEventFn([](Archimedes::Event* e){
if(e->userData.type() == typeid(SDL_Event*)) {
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e->userData));
}
});
#endif
//Compute first frame ahead of first WindowModule->run()
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
bool ImguiModule::onEvent(const Archimedes::Event &e) {
/*
#if WINDOW == 2
if(e.userData != nullptr) {
unsigned int type = app->getEventType(e);
if(type == app->getEventType(Archimedes::ResizeWindowEvent())
|| type == app->getEventType(Archimedes::CloseWindowEvent())
|| type == app->getEventType(Archimedes::KeyPressedWindowEvent())
|| type == app->getEventType(Archimedes::KeyReleasedWindowEvent())
|| type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())
|| type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())
|| type == app->getEventType(Archimedes::ScrollWindowEvent())
|| type == app->getEventType(Archimedes::MouseMovedWindowEvent())
|| type == app->getEventType(Archimedes::FocusedWindowEvent())
|| type == app->getEventType(Archimedes::FocusLostWindowEvent())
|| type == app->getEventType(Archimedes::MovedWindowEvent())) {
ImGui_ImplSDL3_ProcessEvent((SDL_Event*) e.userData);
}
}
#endif
*/
return false;
}

View File

@@ -1,31 +1,71 @@
#include "ImguiEmbed.h"
bool ImguiEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}
void ImguiEmbed::run() {
for(auto m : runOrder)
for(std::string m : runOrder) {
modules[m]->onLoad();
}
// Main loop
while (!done && !runOrder.empty()) {
for(auto m : runOrder) {
for(std::string m : runOrder) {
modules[m]->run();
}
for(auto m : toClose) {
handleEvents();
for(std::string m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
static Archimedes::Module* n;
if(std::holds_alternative<std::string>(m)) {
load(std::get<std::string>(m))->onLoad();
n = load(std::get<std::string>(m));
} else {
load(std::get<Archimedes::Module*>(m))->onLoad();
n = load(std::get<Archimedes::Module*>(m));
}
if(n) {
n->onLoad();
n = nullptr;
}
}
toOpen.clear();
}
}

View File

@@ -1,7 +1,7 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Archimedes-Modules/TestImgui/TestImgui.h"
#include "modules/MainGUI/MainGUI.h"
class ImguiEmbed : public Archimedes::App {
@@ -13,7 +13,7 @@ class ImguiEmbed : public Archimedes::App {
public:
ImguiEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new TestImgui(Get(), nullptr);
Archimedes::Module* m = (Archimedes::Module*) new MainGUI(Get(), nullptr);
load(m);
};

View File

@@ -0,0 +1,55 @@
{ inputs, ... }: {
perSystem = { lib, system, pkgs, ... }: {
packages.exampleApps_ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
$src/example_apps/ImguiEmbed/*.cpp \
$src/modules/MainGUI/*.cpp \
$src/modules/WindowModule/*.cpp \
$src/modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-I $src/include -I $imgui -I $src \
-lEGL -lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,38 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.exampleApps_MinimalApp = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = inputs.src;
outputs = [ "out" "dev" ];
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
$src/example_apps/MinimalApp/MinimalApp.cpp \
-I $src/include \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
mkdir -p $dev/include/modules
cp -r include/* $dev/include
cp -r modules $dev/include/modules
'';
};
};
}

View File

@@ -0,0 +1,71 @@
#include "SandboxEmbed.h"
bool SandboxEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}
void SandboxEmbed::run() {
for(std::string m : runOrder) {
modules[m]->onLoad();
}
// Main loop
while (!done && !runOrder.empty()) {
for(std::string m : runOrder) {
modules[m]->run();
}
handleEvents();
for(std::string m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
static Archimedes::Module* n;
if(std::holds_alternative<std::string>(m)) {
n = load(std::get<std::string>(m));
} else {
n = load(std::get<Archimedes::Module*>(m));
}
if(n) {
n->onLoad();
n = nullptr;
}
}
toOpen.clear();
}
}

View File

@@ -0,0 +1,29 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Archimedes-Modules/Sandbox/Sandbox.h"
class SandboxEmbed : public Archimedes::App {
private:
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
SandboxEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new Sandbox(Get(), nullptr);
load(m);
};
~SandboxEmbed() {};
void handleArgs(const int& argc, char* argv[]) override {};
void run() override;
};
#define APP_TYPE SandboxEmbed
#include "endApp.h"

View File

@@ -0,0 +1,56 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.exampleApps_Sandbox = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
stb
];
buildPhase = ''
clang++ \
example_apps/SandboxEmbed/*.cpp \
modules/Archimedes-Modules/Sandbox/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-I include -I $imgui -I . \
-lEGL -lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
}; };
}

View File

@@ -12,6 +12,8 @@ void TerminalEmbed::run() {
modules[m]->run();
}
handleEvents();
for(auto m : toClose) {
unload(m);
}
@@ -29,3 +31,36 @@ void TerminalEmbed::run() {
}
bool TerminalEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}

View File

@@ -0,0 +1,54 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.exampleApps_TerminalEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
curl
glm
nlohmann_json
];
buildPhase = ''
clang++ \
example_apps/TerminalEmbed/*.cpp \
modules/Archimedes-Modules/Terminal/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-I include -I $imgui -I . \
-lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,71 @@
#include "TriangleEmbed.h"
bool TriangleEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}
void TriangleEmbed::run() {
for(std::string m : runOrder) {
modules[m]->onLoad();
}
// Main loop
while (!done && !runOrder.empty()) {
for(std::string m : runOrder) {
modules[m]->run();
}
handleEvents();
for(std::string m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
static Archimedes::Module* n;
if(std::holds_alternative<std::string>(m)) {
n = load(std::get<std::string>(m));
} else {
n = load(std::get<Archimedes::Module*>(m));
}
if(n) {
n->onLoad();
n = nullptr;
}
}
toOpen.clear();
}
}

View File

@@ -0,0 +1,29 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Archimedes-Modules/TestTriangle/TestTriangle.h"
class TriangleEmbed : public Archimedes::App {
private:
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
TriangleEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new TestTriangle(Get(), nullptr);
load(m);
};
~TriangleEmbed() {};
void handleArgs(const int& argc, char* argv[]) override {};
void run() override;
};
#define APP_TYPE TriangleEmbed
#include "endApp.h"

View File

@@ -0,0 +1,49 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.exampleApps_TriangleEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
example_apps/TriangleEmbed/*.cpp \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-I include -I . \
-lEGL -lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
}; };
}

12
src/include/extratools.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef EXTRATOOLS_H
#define EXTRATOOLS_H
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <nlohmann/json.hpp>
#include <curl/curl.h>
#endif

View File

@@ -2,6 +2,8 @@
#define PCH_HPP
#include <iostream>
#include <memory>
#include <fstream>
#include <cstring>
#include <cassert>
#include <list>
@@ -17,6 +19,7 @@
#include <optional>
#include <chrono>
//#include <thread>
#include <concepts>
#include <dlfcn.h>

View File

@@ -0,0 +1,32 @@
#ifndef BODY_H
#define BODY_H
#include "pch.hpp"
#include "extratools.h"
#include "Object.h"
namespace Archimedes {
class Body : public Object {
public:
Body(RenderTarget rt, glm::mat4 t = glm::mat4(1.0f)) : Object(t), mesh(rt) {};
Body(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> tex = std::nullopt, RenderMode rm = RenderMode::Triangles, glm::mat4 t = glm::mat4(1.0f))
: Object(t), mesh(vb, ia, vl, s, tex, rm) {}
Body() : Object(glm::mat4(1.0f)) {}
~Body() {};
RenderTarget& getMesh() { return mesh; }
private:
RenderTarget mesh;
};
}
#endif

View File

@@ -0,0 +1,30 @@
#ifndef CAMERA_H
#define CAMERA_H
#include "pch.hpp"
#include "extratools.h"
#include "Object.h"
namespace Archimedes {
class Camera : public Object {
public:
Camera() : Object(glm::mat4(1.0f)) {}
Camera(glm::mat4 t)
: Object(t) {}
~Camera() {};
const glm::mat4& getPerspective() { return perspective; }
void setPerspective(const glm::mat4 m) { perspective = m; }
private:
glm::mat4 perspective = glm::mat4(1.0f);
};
}
#endif

View File

@@ -0,0 +1,82 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "pch.hpp"
#include "extratools.h"
#include "utils/Renderer/RenderTarget.h"
namespace Archimedes {
class Object {
public:
Object(glm::mat4 t)
: worldTransform(t) {}
~Object() {};
///scales an object absolutely
///scale factors less than zero do nothing
float scaleTo(float s) {
if(s > 0) {
worldTransform = glm::scale(worldTransform, glm::vec3(s / scale));
scale = s;
}
return scale;
}
float scaleRel(float s) {
return scaleTo(scale * s);
}
float scaleAdd(float s) {
return scaleTo(scale + s);
}
glm::vec3 moveTo(glm::vec3 pos) {
worldTransform = glm::translate(worldTransform, pos - position);
position = pos;
return position;
}
glm::vec3 moveRel(glm::vec3 pos) {
return moveTo(pos + position);
}
glm::vec3 rotateTo(glm::vec3 angles) {
worldTransform = glm::rotate(worldTransform, angles.x - rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
worldTransform = glm::rotate(worldTransform, angles.y - rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
worldTransform = glm::rotate(worldTransform, angles.z - rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
rotation = angles;
return rotation;
}
glm::vec3 rotateRel(glm::vec3 angles) {
return rotateTo(angles + rotation);
}
glm::vec3& getPosition() { return position; }
glm::vec3& getRotation() { return rotation; }
float& getScale() { return scale; }
const glm::mat4& getTransform() { return worldTransform; }
void setTransform(const glm::mat4 m) { worldTransform = m; }
private:
glm::vec3 position = glm::vec3(0);
glm::vec3 rotation = glm::vec3(0);
float scale = 1.0f;
glm::mat4 worldTransform = glm::mat4(1.0f);
};
}
#endif

View File

@@ -0,0 +1,321 @@
#ifndef RENDERTARGET_H
#define RENDERTARGET_H
#include "pch.hpp"
#include "extratools.h"
namespace Archimedes {
enum class RenderMode {
Points,
Lines,
ConnectedLines,
ConnectedLinesLooped,
Triangles,
Quads,
Polygon
};
class Texture {
public:
Texture() {}
Texture(std::vector<unsigned char> bin, size_t width, size_t height)
: bin(bin), width(width), height(height) {}
~Texture() {}
const void* getBin() { return bin.data(); }
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
size_t getWidth() { return width; }
size_t getHeight() { return height; }
unsigned int id;
private:
std::vector<unsigned char> bin;
bool active = false;
size_t width, height;
};
class LayoutElement {
public:
enum class Type {
Float,
UInt,
Int,
Double
};
LayoutElement(Type type, size_t count, size_t stride, size_t offset)
: type(type), count(count), stride(stride), offset(offset) {}
~LayoutElement() {}
Type getType() const { return type; }
size_t getCount() const { return count; }
size_t getStride() const { return stride; }
size_t getOffset() const { return offset; }
private:
Type type;
size_t count;
size_t stride;
size_t offset;
};
class VertexLayout {
public:
VertexLayout() {}
VertexLayout(std::vector<LayoutElement> elements) : elements(elements) {}
~VertexLayout() {}
std::vector<LayoutElement>& getElements() { return elements; }
private:
std::vector<LayoutElement> elements;
};
class VertexBuffer {
public:
VertexBuffer(const std::vector<float> data) : data(data) {
}
VertexBuffer() {}
~VertexBuffer() {}
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
const void* getData() const { return data.data(); }
size_t getSize() const { return data.size() * sizeof(float); }
unsigned int id;
private:
bool active = false;
std::vector<float> data;
};
class VertexArray {
public:
VertexArray() {
}
~VertexArray() {}
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
unsigned int id;
private:
bool active = false;
};
class IndexArray {
public:
IndexArray(const std::vector<unsigned int> indices) : indices(indices) {
}
IndexArray() {}
~IndexArray() {}
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
const void* getIndicies() const { return indices.data(); }
size_t getCount() const { return indices.size(); }
unsigned int id;
private:
bool active = false;
std::vector<unsigned int> indices;
};
class Shader {
public:
enum class LoadType {
FromSource,
FromBin,
FromFileSource,
FromFileBin
};
Shader() {}
Shader(const std::string& vs, const std::string& fs, LoadType loadType) {
init(vs, fs, loadType);
}
~Shader() {}
void init(const std::string& vs, const std::string& fs, LoadType loadType) {
switch(loadType) {
case LoadType::FromSource:
this->shader = source { vs, fs };
break;
case LoadType::FromBin:
break;
case LoadType::FromFileSource:
this->shader = source {
readSourceFile(vs),
readSourceFile(fs)
};
break;
case LoadType::FromFileBin:
break;
default:
break;
}
}
void init(const std::vector<unsigned char>& vs, const std::vector<unsigned char>& fs, LoadType loadType) {
switch(loadType) {
case LoadType::FromSource:
break;
case LoadType::FromBin:
this->shader = bin { vs, fs };
break;
case LoadType::FromFileSource:
break;
case LoadType::FromFileBin:
break;
default:
break;
}
}
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
std::string getVSource() const { return std::get<source>(shader).vertex; }
std::string getFSource() const { return std::get<source>(shader).fragment; }
std::vector<unsigned char>& getVbin() { return std::get<bin>(shader).vertex; }
std::vector<unsigned char>& getFbin() { return std::get<bin>(shader).fragment; }
unsigned int id;
private:
struct source {
std::string vertex;
std::string fragment;
};
struct bin {
std::vector<unsigned char> vertex;
std::vector<unsigned char> fragment;
};
std::variant<source, bin> shader;
bool active = false;
std::string readSourceFile(const std::string& path) {
std::ifstream file(path);
if(!file.is_open()) {
return "";
}
std::string s;
while(!file.eof()) {
file >> s;
}
return s;
}
std::vector<unsigned char> readBinFile(const std::string& path) {
std::ifstream file(path, std::ios::binary);
if(!file.is_open()) {
return std::vector<unsigned char>();
}
std::vector<unsigned char> s;
s.reserve(10000);
while(!file.eof()) {
s.push_back(file.get());
}
return s;
}
};
class RenderTarget {
public:
RenderTarget(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> t = std::nullopt, RenderMode rm = RenderMode::Triangles)
: vertexBuffer(vb),
indexArray(ia),
layout(vl),
shader(s),
texture(t),
renderMode(rm) {
}
RenderTarget() {}
~RenderTarget() {}
void setup(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> t = std::nullopt, RenderMode rm = RenderMode::Triangles) {
vertexBuffer = vb;
indexArray = ia;
layout = vl;
shader = s;
texture = t;
renderMode = rm;
}
void setActive(bool b) { active = b; }
const bool getActive() const { return active; }
//private:
VertexBuffer vertexBuffer;
VertexArray vertexArray;
IndexArray indexArray;
VertexLayout layout;
Shader shader;
std::optional<Texture> texture;
RenderMode renderMode;
bool active = false;
};
}
#endif

View File

@@ -0,0 +1,54 @@
#ifndef RENDERER_H
#define RENDERER_H
#include "pch.hpp"
#include "extratools.h"
#include "RenderTarget.h"
namespace Archimedes {
class Renderer {
public:
int w, h;
glm::vec4 clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
Renderer() : w(0), h(0) {}
virtual ~Renderer() {}
virtual bool init() = 0;
virtual void render() = 0;
virtual void setupShader(Shader& shader) = 0;
virtual void setupTexture(Texture& texture) = 0;
virtual void updateTexture(Texture& texture) = 0;
virtual void setupRenderTarget(RenderTarget& rt) = 0;
virtual void updateRenderTarget(RenderTarget& rt) = 0;
virtual void freeRenderTarget(RenderTarget& rt) = 0;
virtual void draw(
const RenderTarget& rt,
const glm::mat4 world = glm::mat4(1.0f),
const glm::mat4 view = glm::mat4(1.0f),
const glm::mat4 proj = glm::mat4(1.0f),
const glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }
) = 0;
virtual Renderer* getRendererImpl() = 0;
};
}
#endif

View File

@@ -0,0 +1,278 @@
#ifdef RENDERER_OPENGL
#ifndef RENDERER_OPENGL_H
#define RENDERER_OPENGL_H
#include "pch.hpp"
#include "utils/Renderer/Renderer.h"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
class RendererOpenGL : public Renderer {
public:
typedef void renderCmd();
RendererOpenGL() {};
~RendererOpenGL() {};
bool init() override {
bool ok = glewInit() == GLEW_OK;
if(ok) {
glEnable(GL_DEPTH_TEST);
}
return ok;
};
void render() override {
glViewport(0, 0, w, h);
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void setupShader(Shader& shader) override {
std::string vss = shader.getVSource();
std::string fss = shader.getFSource();
const char* vsc = vss.c_str();
const char* fsc = fss.c_str();
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vsc, NULL);
glCompileShader(vertexShader);
// check for shader compile errors
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
// fragment shader
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fsc, NULL);
glCompileShader(fragmentShader);
// check for shader compile errors
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}
// link shaders
unsigned int shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
// check for linking errors
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
shader.id = shaderProgram;
}
void setupTexture(Texture& texture) override {
glGenTextures(1, &texture.id);
updateTexture(texture);
}
void updateTexture(Texture& texture) override {
glBindTexture(GL_TEXTURE_2D, texture.id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture.getWidth(), texture.getHeight(), 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture.getBin());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
void setupRenderTarget(RenderTarget& rt) override {
glGenVertexArrays(1, &rt.vertexArray.id);
glGenBuffers(1, &rt.vertexBuffer.id);
glGenBuffers(1, &rt.indexArray.id);
rt.vertexArray.setActive(true);
rt.vertexBuffer.setActive(true);
rt.indexArray.setActive(true);
if(rt.texture.has_value()) {
glGenTextures(1, &rt.texture.value().id);
rt.texture.value().setActive(true);
}
updateRenderTarget(rt);
rt.setActive(true);
};
void updateRenderTarget(RenderTarget& rt) override {
if(rt.vertexArray.getActive()) {
glBindVertexArray(rt.vertexArray.id);
if(rt.vertexBuffer.getActive()) {
glBindBuffer(GL_ARRAY_BUFFER, rt.vertexBuffer.id);
glBufferData(GL_ARRAY_BUFFER, rt.vertexBuffer.getSize(), rt.vertexBuffer.getData(), GL_STATIC_DRAW);
}
if(rt.indexArray.getActive()) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rt.indexArray.id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, rt.indexArray.getCount() * sizeof(unsigned int), rt.indexArray.getIndicies(), GL_STATIC_DRAW);
}
if(rt.texture.has_value()) {
if(rt.texture.value().getActive()) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rt.texture.value().id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt.texture.value().getWidth(), rt.texture.value().getHeight(), 0, GL_RED, GL_UNSIGNED_BYTE, rt.texture.value().getBin());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
}
if(rt.shader.getActive()) {
glUseProgram(rt.shader.id);
}
unsigned int i = 0;
for(LayoutElement e : rt.layout.getElements()) {
switch(e.getType()) {
case LayoutElement::Type::Float:
glVertexAttribPointer(i, e.getCount(), GL_FLOAT, GL_FALSE, e.getStride(), (void*)e.getOffset());
glEnableVertexAttribArray(i);
break;
case LayoutElement::Type::Double:
glVertexAttribPointer(i, e.getCount(), GL_DOUBLE, GL_FALSE, e.getStride(), (void*)e.getOffset());
glEnableVertexAttribArray(i);
break;
case LayoutElement::Type::Int:
glVertexAttribPointer(i, e.getCount(), GL_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
glEnableVertexAttribArray(i);
break;
case LayoutElement::Type::UInt:
glVertexAttribPointer(i, e.getCount(), GL_UNSIGNED_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
glEnableVertexAttribArray(i);
break;
default:
break;
}
i++;
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
};
void freeRenderTarget(RenderTarget& rt) override {
glDeleteVertexArrays(1, &rt.vertexArray.id);
glDeleteBuffers(1, &rt.vertexBuffer.id);
glDeleteBuffers(1, &rt.indexArray.id);
rt.vertexArray.setActive(false);
rt.vertexBuffer.setActive(false);
rt.indexArray.setActive(false);
rt.setActive(false);
};
void draw(
const RenderTarget& rt,
const glm::mat4 world = glm::mat4(1.0f),
const glm::mat4 view = glm::mat4(1.0f),
const glm::mat4 proj = glm::mat4(1.0f),
const glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }
) override {
glUseProgram(rt.shader.id);
unsigned int modelLoc = glGetUniformLocation(rt.shader.id, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(world));
unsigned int viewLoc = glGetUniformLocation(rt.shader.id, "view");
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
unsigned int projLoc = glGetUniformLocation(rt.shader.id, "proj");
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj));
unsigned int colorLoc = glGetUniformLocation(rt.shader.id, "color");
glUniform4f(colorLoc, color.r, color.g, color.b, color.a);
if(rt.texture.has_value()) {
if(rt.texture.value().getActive()) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rt.texture.value().id);
glUniform1i(glGetUniformLocation(rt.shader.id, "tex"), 0);
}
}
glBindVertexArray(rt.vertexArray.id);
switch(rt.renderMode) {
case RenderMode::Triangles:
glDrawElements(GL_TRIANGLES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::Lines:
glDrawElements(GL_LINES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::ConnectedLines:
glDrawElements(GL_LINE_STRIP, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::ConnectedLinesLooped:
glDrawElements(GL_LINE_LOOP, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::Quads:
glDrawElements(GL_QUADS, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::Polygon:
glDrawElements(GL_POLYGON, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
case RenderMode::Points:
glDrawElements(GL_POINTS, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
break;
default:
break;
}
glBindVertexArray(0);
}
RendererOpenGL* getRendererImpl() override { return this; }
};
}
#endif
#endif

View File

@@ -1,7 +1,6 @@
#if RENDERER == 2
#ifndef RENDERER_SDL3
#define RENDERER_SDL3
#ifdef RENDERER_SDL3
#ifndef RENDERER_SDL3_H
#define RENDERER_SDL3_H
#include "pch.hpp"
@@ -38,12 +37,7 @@ namespace Archimedes {
SDL_Renderer* renderer = nullptr;
};
typedef RendererSDL3 RendererImpl;
}
#endif
#endif

View File

@@ -0,0 +1,66 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "WindowEvents.h"
#include "utils/Renderer/Renderer.h"
namespace Archimedes {
class Window {
public:
Window(const std::function<void(Event*)>& sendEventFn) : eventFn(sendEventFn) {}
virtual ~Window() {};
void doFrame() {
swapBuffers();
renderer->render();
pollEvents();
}
virtual bool shouldClose() = 0;
virtual void swapBuffers() = 0;
virtual void pollEvents() = 0;
virtual void restoreContext() = 0;
virtual void getSize(int& w, int& h) {
w = this->w;
h = this->h;
}
virtual void setSize(const int& w, const int& h) {
this->w = w;
this->h = h;
}
Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) {
renderer = r;
renderer->w = w;
renderer->h = h;
}
virtual Window* getWindowImpl() = 0;
protected:
int w, h;
Renderer* renderer;
std::function<void(Event*)> eventFn;
};
}
#endif

View File

@@ -1,11 +1,10 @@
#if WINDOW == 1
#ifndef WINDOW_GLFW
#define WINDOW_GLFW
#ifdef WINDOW_GLFW
#ifndef WINDOW_GLFW_H
#define WINDOW_GLFW_H
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
@@ -13,20 +12,13 @@
namespace Archimedes {
class Window;
class WindowGLFW {
class WindowGLFW : public Window {
public:
WindowGLFW(Window* p, const std::function<void(Event*)>& sendEvent) {
WindowGLFW(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
/*if(glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
}*/
data.window = p;
data.window = this;
data.sendEvent = sendEvent;
glfwSetErrorCallback([](int e, const char* m){
@@ -37,31 +29,39 @@ namespace Archimedes {
std::cout << "glfwInit failed!\n";
std::abort();
}
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
#ifdef RENDERER_OPENGL
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if(!w) {
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
#endif
window = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!window) {
std::cout << "glfwCreateWindow failed!\n";
glfwTerminate();
std::abort();
}
glfwMakeContextCurrent(w);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowUserPointer(w, &data);
glfwSetWindowUserPointer(window, &data);
glfwSetWindowSizeCallback(w, [](GLFWwindow* window, int w, int h){
glfwSetWindowSizeCallback(window, [](GLFWwindow* window, int w, int h){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new ResizeWindowEvent(w, h));
});
glfwSetWindowCloseCallback(w, [](GLFWwindow* window){
glfwSetWindowCloseCallback(window, [](GLFWwindow* window){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new CloseWindowEvent(d.window));
});
glfwSetKeyCallback(w, [](GLFWwindow* window, int key, int scancode, int action, int mods){
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) {
@@ -77,7 +77,7 @@ namespace Archimedes {
}
});
glfwSetMouseButtonCallback(w, [](GLFWwindow* window, int button, int action, int mods){
glfwSetMouseButtonCallback(window, [](GLFWwindow* window, int button, int action, int mods){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) {
@@ -90,13 +90,13 @@ namespace Archimedes {
}
});
glfwSetScrollCallback(w, [](GLFWwindow* window, double dx, double dy){
glfwSetScrollCallback(window, [](GLFWwindow* window, double dx, double dy){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new ScrollWindowEvent(dx, dy));
});
glfwSetCursorPosCallback(w, [](GLFWwindow* window, double dx, double dy){
glfwSetCursorPosCallback(window, [](GLFWwindow* window, double dx, double dy){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new MouseMovedWindowEvent(dx, dy));
@@ -108,33 +108,39 @@ namespace Archimedes {
}
bool shouldClose() {
return glfwWindowShouldClose(w);
void swapBuffers() override { restoreContext(); glfwSwapBuffers(window); };
void pollEvents() override { glfwPollEvents(); }
bool shouldClose() override {
return glfwWindowShouldClose(window);
}
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
void setSize(const int& w, const int& h) override {
this->w = w;
this->h = h;
void pollEvents() { glfwPollEvents(); }
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
glfwSetWindowSize(window, w, h);
}
GLFWwindow* getWindow() { return w; }
void restoreContext() override { glfwMakeContextCurrent(window); }
void getSize(int& w, int& h) override {
glfwGetFramebufferSize(window, &w, &h);
}
GLFWwindow* getWindow() { return window; }
WindowData data;
virtual WindowGLFW* getWindowImpl() override { return this; }
private:
GLFWwindow* w;
GLFWwindow* window;
};
typedef WindowGLFW WindowImpl;
}
#endif
#endif

View File

@@ -1,15 +1,14 @@
#if WINDOW == 2
#ifndef WINDOW_SDL3
#define WINDOW_SDL3
#ifdef WINDOW_SDL3
#ifndef WINDOW_SDL3_H
#define WINDOW_SDL3_H
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#include <SDL3/SDL.h>
#if RENDERER == 2
#ifdef RENDERER_OPENGL
#include <SDL3/SDL_opengl.h>
@@ -17,8 +16,6 @@
namespace Archimedes {
class Window;
static bool EventCallback(void* ptr, SDL_Event* e) {
WindowData& data = *(WindowData*) ptr;
@@ -66,13 +63,13 @@ namespace Archimedes {
return true;
}
class WindowSDL3 {
class WindowSDL3 : public Window {
public:
WindowSDL3(Window* p, const std::function<void(Event*)>& sendEvent) {
WindowSDL3(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
data.window = p;
data.window = this;
data.sendEvent = sendEvent;
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
@@ -80,26 +77,27 @@ namespace Archimedes {
std::abort();
}
#if RENDERER == 1
#ifdef RENDERER_OPENGL
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
#elif RENDERER == 2
#endif
#ifdef RENDERER_SDL3
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
#endif
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (w == nullptr)
window = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (window == nullptr)
{
std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl;
std::abort();
}
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
#if RENDERER == 1
gl_context = SDL_GL_CreateContext(w);
#ifdef RENDERER_OPENGL
gl_context = SDL_GL_CreateContext(window);
if (gl_context == nullptr)
{
@@ -107,67 +105,57 @@ namespace Archimedes {
std::abort();
}
SDL_GL_MakeCurrent(w, gl_context);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
#endif
SDL_AddEventWatch(EventCallback, &data);
SDL_ShowWindow(w);
SDL_ShowWindow(window);
}
~WindowSDL3() {
#if RENDERER == 1
#ifdef RENDERER_OPENGL
SDL_GL_DestroyContext(gl_context);
#endif
SDL_RemoveEventWatch(EventCallback, &data);
SDL_DestroyWindow(w);
SDL_DestroyWindow(window);
SDL_Quit();
}
bool shouldClose() { return false; }
bool shouldClose() override { return false; }
void doFrame() {
#if RENDERER == 1
void swapBuffers() override {
#ifdef RENDERER_OPENGL
restoreContext();
SDL_GL_SwapWindow(w);
SDL_GL_SwapWindow(window);
#endif
}
void pollEvents() {
void pollEvents() override {
static SDL_Event e;
while(SDL_PollEvent(&e)) {}
while(SDL_PollEvent(&e));
}
#if RENDERER == 1
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
WindowSDL3* getWindowImpl() override { return this; };
#ifdef RENDERER_OPENGL
void restoreContext() override { SDL_GL_MakeCurrent(window, gl_context); }
#endif
void getSize(int& w, int& h) {
w = this->width;
h = this->height;
}
void setSize(int& w, int& h) {
this->width = w;
this->height = h;
}
SDL_Window* getWindow() { return w; }
#if RENDERER == 1
SDL_Window* getWindow() { return window; }
#ifdef RENDERER_OPENGL
SDL_GLContext getContext() { return gl_context; }
#endif
WindowData data;
private:
SDL_Window* w;
int width = 0, height = 0;
#if RENDERER == 1
SDL_Window* window;
#ifdef RENDERER_OPENGL
SDL_GLContext gl_context;
#endif
};
typedef WindowSDL3 WindowImpl;
}
#endif
#endif

View File

@@ -151,6 +151,8 @@ double Calculator::evaluate(std::string equation, std::unordered_map<char, std::
default:
break;
}
return 0;
}
std::string Calculator::calculate(std::string equation) {

View File

@@ -17,7 +17,7 @@ class Calculator : public Archimedes::Module {
bool parenthesis = true;
bool graphing = false;
//bool graphing = false;
void basicCalculator();

View File

@@ -0,0 +1,56 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.Calculator = pkgs.stdenvNoCC.mkDerivation {
name = "Calculator";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Calculator/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-DCALCULATOR_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,54 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChatClient = pkgs.stdenvNoCC.mkDerivation {
name = "ChatClient";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
modules/ClientModule/*.cpp \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCHATCLIENT_DYNAMIC \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,41 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChatServer = pkgs.stdenvNoCC.mkDerivation {
name = "ChatServer";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
modules/ServerModule/*.cpp \
-fpic -shared \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-I include -I . \
-lGameNetworkingSockets \
-DCHATSERVER_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,54 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChatClientVoice = pkgs.stdenvNoCC.mkDerivation {
name = "ChatClientVoice";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
sdl3
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/ChatVoice/ChatClientVoice/*.cpp \
modules/ClientModule/*.cpp \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCHATCLIENTVOICE_DYNAMIC \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_sdl3.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=2 \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lSDL3 -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,41 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChatServerVoice = pkgs.stdenvNoCC.mkDerivation {
name = "ChatServerVoice";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/ChatVoice/ChatServerVoice/*.cpp \
modules/ServerModule/*.cpp \
-fpic -shared \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-I include -I . \
-lGameNetworkingSockets \
-DCHATSERVERVOICE_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,54 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChessClient = pkgs.stdenvNoCC.mkDerivation {
name = "ChatClient";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
modules/ClientModule/*.cpp \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCHATCLIENT_DYNAMIC \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,41 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ChessServer = pkgs.stdenvNoCC.mkDerivation {
name = "ChatServer";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
modules/ServerModule/*.cpp \
-fpic -shared \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-I include -I . \
-lGameNetworkingSockets \
-DCHATSERVER_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -1,7 +1,6 @@
#include "Archimedes.h"
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include "extratools.h"
class Ollama : public Archimedes::Module {

View File

@@ -0,0 +1,55 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.Ollama = pkgs.stdenvNoCC.mkDerivation {
name = "Ollama";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
curl
nlohmann_json
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Ollama/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DOLLAMA_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,34 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.Print = pkgs.stdenvNoCC.mkDerivation {
name = "Print";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Print/*.cpp \
-fpic -shared \
-I include \
-Wall \
-DPRINT_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,453 @@
#include "pch.hpp"
#include "utils/Objects/Body.h"
#include <stb/stb_truetype.h>
#include <stb/stb_image_write.h>
#include <GL/glew.h>
namespace Archimedes {
class Text {
unsigned int tex;
std::vector<unsigned char> ttf;
stbtt_bakedchar bcdata[96];
std::string fontPath;
std::string vs = "#version 430 core\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTex;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 proj;\n"
"out vec2 TexCoord;\n"
"void main()\n"
"{\n"
" gl_Position = proj * view * model * vec4(aPos.x, 1.0f - aPos.y, aPos.z, 1.0);\n"
" TexCoord = aTex;\n"
"}\0";
std::string fs = "#version 430 core\n"
"out vec4 FragColor;\n"
"in vec2 TexCoord;\n"
"uniform sampler2D tex;\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
" FragColor = vec4(color.rgb, texture(tex, TexCoord).r);\n"
"}\n\0";
public:
Shader shader;
Texture texture;
float fontSize = 200.0f;
Text() {}
~Text() {}
void textInit(std::string p) {
fontPath = p;
unsigned char temp_bitmap[1024*1024];
std::ifstream file(fontPath, std::ios::binary);
file.seekg(0, std::ios::end);
auto&& size = file.tellg();
file.seekg(0, std::ios::beg);
ttf.reserve(size);
if(!file.is_open()) {
std::cout << "ttf won't open!\n";
}
while(!file.eof()) {
ttf.push_back(file.get());
}
file.close();
stbtt_BakeFontBitmap(ttf.data(),0, fontSize, temp_bitmap,1024,1024, 32,96, bcdata);
std::vector<unsigned char> bin;
bin.reserve(1024 * 1024);
for(unsigned char c : temp_bitmap) {
bin.push_back(c);
}
texture = Texture(bin, 1024, 1024);
shader = Shader(vs, fs, Shader::LoadType::FromSource);
}
Body* genText(std::vector<std::string> texts) {
std::vector<float> v;
std::vector<unsigned int> i;
float x = 0, y = 0, oX = 0, dY = fontSize;
unsigned int k = 0;
for(std::string text : texts) {
for(unsigned int j = 0; j < text.length(); j++) {
if (text[j] >= 32) {
stbtt_aligned_quad q;
stbtt_GetBakedQuad(bcdata, 1024,1024, text[j]-32, &x,&y,&q,0);//1=opengl & d3d10+,0=d3d9
//bcdata[text[j]-32].xadvance
v.push_back(q.x0);
v.push_back(q.y0);
v.push_back(0.0f);
v.push_back(q.s0);
v.push_back(q.t0);
v.push_back(q.x1);
v.push_back(q.y0);
v.push_back(0.0f);
v.push_back(q.s1);
v.push_back(q.t0);
v.push_back(q.x1);
v.push_back(q.y1);
v.push_back(0.0f);
v.push_back(q.s1);
v.push_back(q.t1);
v.push_back(q.x0);
v.push_back(q.y1);
v.push_back(0.0f);
v.push_back(q.s0);
v.push_back(q.t1);
i.push_back(k * 4);
i.push_back(k * 4 + 1);
i.push_back(k * 4 + 2);
i.push_back(k * 4 + 2);
i.push_back(k * 4 + 3);
i.push_back(k * 4);
k++;
}
}
x = oX;
y += dY;
}
return new Body(
VertexBuffer(v),
IndexArray(i),
VertexLayout({
LayoutElement(LayoutElement::Type::Float, 3, 5 * sizeof(float), 0),
LayoutElement(LayoutElement::Type::Float, 2, 5 * sizeof(float), 3 * sizeof(float))
}),
shader,
texture,
RenderMode::Triangles,
glm::scale(glm::mat4(1.0f), glm::vec3(0.2f))
);
}
float textWidth(std::string str, float height) {
float w = 0;
for (int i = 0; i < str.length(); i++) {
stbtt_bakedchar c = bcdata[str[i]];
w += c.xadvance;
}
return w * height / fontSize;
}
};
using json = nlohmann::json;
class JObject {
public:
JObject() {}
void load(std::string pathJSON, std::string pathFont) {
std::ifstream file(pathJSON);
if (!file.is_open()) goodJSON = false;
document = json::parse(file);
file.close();
goodJSON = true;
templates = document["Templates"];
objects = document["Objects"];
setup = document["Set Up"];
cameras = document["Cameras"];
lights = document["Lights"];
actions = document["Actions"];
text.textInit(pathFont);
}
bool isValid() const { return goodJSON; }
Body* createCircle(json& element, std::string name) {
std::vector<float> v;
std::vector<unsigned int> i;
float d = element["diameter"];
for(int it = 0; it < resolution; it++) {
v.push_back(d / 2.0f * glm::cos(it * 2.0f * glm::pi<float>() / resolution));
v.push_back(d / 2.0f * glm::sin(it * 2.0f * glm::pi<float>() / resolution));
v.push_back(0.0f);
i.push_back(it);
}
return new Body(
VertexBuffer(v),
IndexArray(i),
layout,
shader,
std::nullopt,
RenderMode::ConnectedLinesLooped
);
}
Body* createSquare(json& element, std::string name) {
std::vector<float> v;
std::vector<unsigned int> i;
float width = element["width"];
v.push_back(width / 2.0f);
v.push_back(width / 2.0f);
v.push_back(0.0f);
i.push_back(0);
v.push_back(-width / 2.0f);
v.push_back(width / 2.0f);
v.push_back(0.0f);
i.push_back(1);
v.push_back(-width / 2.0f);
v.push_back(-width / 2.0f);
v.push_back(0.0f);
i.push_back(2);
v.push_back(width / 2.0f);
v.push_back(-width / 2.0f);
v.push_back(0.0f);
i.push_back(3);
return new Body(
VertexBuffer(v),
IndexArray(i),
layout,
shader,
std::nullopt,
RenderMode::ConnectedLinesLooped
);
}
Body* createRect(json& element, std::string name) {
std::vector<float> v;
std::vector<unsigned int> i;
float width = element["width"];
float height = element["height"];
v.push_back(width / 2.0f);
v.push_back(height / 2.0f);
v.push_back(0.0f);
i.push_back(0);
v.push_back(-width / 2.0f);
v.push_back(height / 2.0f);
v.push_back(0.0f);
i.push_back(1);
v.push_back(-width / 2.0f);
v.push_back(-height / 2.0f);
v.push_back(0.0f);
i.push_back(2);
v.push_back(width / 2.0f);
v.push_back(-height / 2.0f);
v.push_back(0.0f);
i.push_back(3);
return new Body(
VertexBuffer(v),
IndexArray(i),
layout,
shader,
std::nullopt,
RenderMode::ConnectedLinesLooped
);
}
Body* createPoly(json& element, std::string name) {
std::vector<float> v;
std::vector<unsigned int> i;
json coords = element["coords"];
unsigned int j = 0;
for(json::const_iterator it = coords.cbegin(); it != coords.cend(); it++) {
json c = *it;
v.push_back(c["x"]);
v.push_back(c["y"]);
v.push_back(c["z"]);
i.push_back(j++);
}
return new Body(
VertexBuffer(v),
IndexArray(i),
layout,
shader,
std::nullopt,
RenderMode::ConnectedLinesLooped
);
}
Body* createText(json& element, std::string name) {
//do something
json lines = element["text"];
std::vector<std::string> theText;
for (json::const_iterator it = lines.cbegin(); it != lines.cend(); it++)
{
std::string line = *it;
theText.push_back(line);
}
return text.genText(theText);
}
void buildObjects() {
for (json::const_iterator it = objects.cbegin(); it != objects.cend(); it++)
{
json element = *it;
std::string name = element["name"];
std::string type = element["type"];
if (type == "CIRCLE") {
objectMap[name] = createCircle(element, name);
}
if (type == "SQUARE") {
objectMap[name] = createSquare(element, name);
}
if (type == "RECTANGLE") {
objectMap[name] = createRect(element, name);
}
if (type == "POLYGON") {
objectMap[name] = createPoly(element, name);
}
if (type == "TEXT") {
objectMap[name] = createText(element, name);
}
}
}
void objectActions()
{
for (json::const_iterator it = setup.cbegin(); it != setup.cend(); it++)
{
json element = *it;
std::string name = element["name"];
Body* o = objectMap[name];
if (o == nullptr) continue;
if (element.contains("moveto"))
{
json moveTo = element["moveto"];
float x = moveTo["x"];
float y = moveTo["y"];
float z = moveTo["z"];
o->moveTo(glm::vec3(x, y, z));
}
if (element.contains("moveby"))
{
json moveBy = element["moveby"];
float x = moveBy["x"];
float y = moveBy["y"];
float z = moveBy["z"];
o->moveRel(glm::vec3(x, y, z));
}
if (element.contains("rotateto"))
{
json rotateTo = element["rotateto"];
float p = rotateTo["pitch"];
float y = rotateTo["yaw"];
float r = rotateTo["roll"];
o->rotateTo(glm::vec3(p, y, r));
}
if (element.contains("rotateby"))
{
json rotateBy = element["rotateby"];
float p = rotateBy["pitch"];
float y = rotateBy["yaw"];
float r = rotateBy["roll"];
o->rotateRel(glm::vec3(p, y, r));
}
}
}
std::unordered_map<std::string, Body*> objectMap;
Shader shader;
Text text;
private:
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
});
std::unordered_map<std::string, Body> templateMap;
bool goodJSON = false;
unsigned int resolution = 50;
json document, templates, objects, setup, cameras, lights, actions;
};
}

View File

@@ -0,0 +1,309 @@
// This only works with opengl!!!!
#include "Sandbox.h"
#define STB_TRUETYPE_IMPLEMENTATION
#include <stb/stb_truetype.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
Sandbox::Sandbox(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "Sandbox";
WindowModule* wm = new WindowModule(a, h);
deps[*wm] = wm;
ImguiModule* im = new ImguiModule(a, h);
deps[*im] = im;
}
Sandbox::~Sandbox() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
wm->releaseWindow(window);
}
}
void Sandbox::onLoad() {
// get window
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!wm) {
std::cout << "No WindowModule for Sandbox!\n";
std::abort();
}
if(!im) {
std::cout << "No ImguiModule for Sandbox!\n";
std::abort();
}
window = wm->aquireWindow();
ImGui::SetCurrentContext(im->aquireContext());
window->getRenderer()->clearColor = { 0.2, 0.2, 0.4, 0.7 };
cubeShader = Archimedes::Shader(cubeVS, cubeFS, Archimedes::Shader::LoadType::FromSource);
window->getRenderer()->setupShader(cubeShader);
cube = Archimedes::Body(
Archimedes::VertexBuffer(vertices),
Archimedes::IndexArray(indices),
layout,
cubeShader
);
window->getRenderer()->setupRenderTarget(cube.getMesh());
grid = Archimedes::Body(
Archimedes::VertexBuffer(gridVertices),
Archimedes::IndexArray(gridIndices),
layout,
cubeShader
);
window->getRenderer()->setupRenderTarget(grid.getMesh());
int w, h;
window->getSize(w, h);
app->emitEvent(new Archimedes::ResizeWindowEvent(w, h));
hexagon = readOBJ("/home/nathan/Projects/tests/buildzone/hexagon_pad.obj", cubeShader);
window->getRenderer()->setupRenderTarget(hexagon.getMesh());
hexagon.scaleTo(0.01f);
camera.setTransform(glm::lookAt(
glm::vec3(0.0f, 0.0f, 3.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f)
));
camera.setPerspective(glm::perspective(glm::radians(45.0f), (float)w/(float)h, 0.1f, 100.0f));
//camera.setPerspective(glm::ortho(-(float)w / 2.0f, (float)w / 2.0f, -(float)h / 2.0f, (float)h / 2.0f, 0.1f, 100.0f));
}
void Sandbox::run() {
static float scale = 1.0f, scalePrev = 1.0f;
static glm::vec3 pos(0), rot(0);
static glm::vec3 posPrev(0), rotPrev(0);
static glm::vec3 camPos(0.0f, 0.0f, 3.0f), camRot(0.0f, glm::pi<float>(), 0.0f);
static glm::vec3 camPosPrev(0.0f, 0.0f, 3.0f), camRotPrev(0.0f, glm::pi<float>(), 0.0f);
static glm::vec4 color = { 0.4f, 3.0f, 0.4f, 1.0f };
static int w, h;
window->getSize(w, h);
//camPos = camera.moveRel(camPos - camPosPrev);
//camRot = camera.rotateRel(camRot - camRotPrev);
camera.setTransform(glm::lookAt(
camPos,
camPos + glm::normalize(glm::vec3(glm::cos(camRot.x) * glm::sin(camRot.y), glm::sin(camRot.x), glm::cos(camRot.x) * glm::cos(camRot.y))),
glm::vec3(0.0f, 1.0f, 0.0f)
));
camPosPrev = camPos;
camRotPrev = camRot;
{
ImGuiIO& io = ImGui::GetIO();
static glm::vec4& clearColor = window->getRenderer()->clearColor;
ImGui::Begin("Sandbox Module");
ImGui::Text("Pick a clear color!");
ImGui::SliderFloat("clear r", &clearColor.r, 0.0f, 1.0f);
ImGui::SliderFloat("clear g", &clearColor.g, 0.0f, 1.0f);
ImGui::SliderFloat("clear b", &clearColor.b, 0.0f, 1.0f);
ImGui::SliderFloat("clear a", &clearColor.a, 0.0f, 1.0f);
if(jObject.isValid()) {
ImGui::Text("Object Properties");
static std::string object = jObject.objectMap.begin()->first;
if(ImGui::BeginCombo("Object", object.c_str())) {
for (auto it : jObject.objectMap)
{
const bool is_selected = (object == it.first);
if (ImGui::Selectable(it.first.c_str(), is_selected)) {
object = it.first;
}
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
for (auto it : jObject.objectMap) {
if(it.second != nullptr) {
window->getRenderer()->draw(
it.second->getMesh(),
it.second->getTransform(),
camera.getTransform(),
camera.getPerspective(),
color
);
}
}
ImGui::SliderFloat("pitch", &rot.x, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("yaw", &rot.y, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("roll", &rot.z, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("scale", &scale, 0.001f, 10.0f);
ImGui::SliderFloat("x", &pos.x, -10.0f, 10.0f);
ImGui::SliderFloat("y", &pos.y, -10.0f, 10.0f);
ImGui::SliderFloat("z", &pos.z, -10.0f, 10.0f);
ImGui::SliderFloat("r", &color.r, 0.0f, 1.0f);
ImGui::SliderFloat("g", &color.g, 0.0f, 1.0f);
ImGui::SliderFloat("b", &color.b, 0.0f, 1.0f);
ImGui::SliderFloat("a", &color.a, 0.0f, 1.0f);
if(ImGui::Button("Apply") && jObject.objectMap[object] != nullptr) {
pos = jObject.objectMap[object]->moveRel(pos - posPrev);
rot = jObject.objectMap[object]->rotateRel(rot - rotPrev);
//scale = jObject.objectMap[object]->scaleRel(scale / scalePrev);
jObject.objectMap[object]->scaleTo(scale / (float)h);
posPrev = pos;
rotPrev = rot;
//scalePrev = scale;
}
} else {
static std::string pathJSON = "/home/nathan/Projects/tests/buildzone/test.json";
static std::string pathFont = "/nix/store/05zf1s3wlw0k90l34iaby4ysrafv6w95-nerd-fonts-fira-code-3.4.0+6.2/share/fonts/truetype/NerdFonts/FiraCode/FiraCodeNerdFontMono-Regular.ttf";
ImGui::InputText("JSON Path", &pathJSON);
ImGui::InputText("Font Path", &pathFont);
if(ImGui::Button("load")) {
jObject.shader = cubeShader;
jObject.load(pathJSON, pathFont);
window->getRenderer()->setupShader(jObject.text.shader);
//window->getRenderer()->setupTexture(jObject.text.texture);
jObject.buildObjects();
for(auto o : jObject.objectMap) {
if(o.second != nullptr) {
o.second->scaleTo(1.0f / (float)h);
window->getRenderer()->setupRenderTarget(o.second->getMesh());
}
}
jObject.objectActions();
}
}
static bool show_obj = true;
ImGui::Checkbox("show obj", &show_obj);
if(show_obj) {
window->getRenderer()->draw(
hexagon.getMesh(),
hexagon.getTransform(),
camera.getTransform(),
camera.getPerspective(),
color
);
}
ImGui::Text("Camera Properties");
ImGui::SliderFloat("cam pitch", &camRot.x, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("cam yaw", &camRot.y, 0, 2 * glm::pi<float>());
ImGui::SliderFloat("cam roll", &camRot.z, -glm::pi<float>(), glm::pi<float>());
ImGui::SliderFloat("cam x", &camPos.x, -10.0f, 10.0f);
ImGui::SliderFloat("cam y", &camPos.y, -10.0f, 10.0f);
ImGui::SliderFloat("cam z", &camPos.z, -10.0f, 10.0f);
if(ImGui::Button("Reset Window Size")) {
app->emitEvent(new Archimedes::ResizeWindowEvent(500, 500));
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
}
}
bool Sandbox::onEvent(const Archimedes::Event& e) {
unsigned int type = app->getEventType(e);
ImGuiIO& io = ImGui::GetIO(); (void)io;
if(type == app->getEventType(Archimedes::ResizeWindowEvent())) {
Archimedes::ResizeWindowEvent event = (Archimedes::ResizeWindowEvent&) e;
camera.setPerspective(glm::perspective(glm::radians(45.0f), (float)event.width/(float)event.height, 0.1f, 100.0f));
} else if(type == app->getEventType(Archimedes::KeyPressedWindowEvent()) && !io.WantCaptureKeyboard) {
return false;
} else if(type == app->getEventType(Archimedes::KeyReleasedWindowEvent()) && !io.WantCaptureKeyboard) {
return false;
} else if(type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent()) && !io.WantCaptureMouse) {
return false;
} else if(type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent()) && !io.WantCaptureMouse) {
return false;
} else if(type == app->getEventType(Archimedes::ScrollWindowEvent()) && !io.WantCaptureMouse) {
Archimedes::ScrollWindowEvent event = (Archimedes::ScrollWindowEvent&) e;
//cube.rotateRel(glm::vec3(glm::pi<float>() * event.dy / 50.0f, 0.0f, 0.0f));
//cube.rotateRel(glm::vec3(0.0f, glm::pi<float>() * event.dx / 50.0f, 0.0f));
hexagon.scaleAdd(0.001f * event.dy);
return true;
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent()) && !io.WantCaptureMouse) {
return false;
}
return false;
}

View File

@@ -0,0 +1,228 @@
// This only works with opengl!!!!
#ifndef JOBJECT_H
#define JOBJECT_H
#include "Archimedes.h"
#include "modules/WindowModule/WindowModule.h"
#include "modules/ImguiModule/ImguiModule.h"
#include "utils/Objects/Body.h"
#include "utils/Objects/Camera.h"
#include "JObject.h"
class Sandbox : public Archimedes::Module {
public:
Sandbox(Archimedes::App*, void*);
Sandbox() { name = "Sandbox"; }
~Sandbox();
void onLoad() override;
void run() override;
bool onEvent(const Archimedes::Event& e) override;
private:
Archimedes::Window* window;
std::string cubeVS = "#version 430 core\n"
"layout (location = 0) in vec3 aPos;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 proj;\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
" gl_Position = proj * view * model * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
std::string cubeFS = "#version 430 core\n"
"out vec4 FragColor;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 proj;\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
" FragColor = color;\n"
"}\n\0";
Archimedes::JObject jObject;
Archimedes::Shader cubeShader, gridShader;
Archimedes::Body cube, grid, hexagon;
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
});
Archimedes::Camera camera;
std::vector<float> gridVertices = {
-1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f,
1.0f, 0.0f, -1.0f,
-1.0f, 0.0f, -1.0f,
};
std::vector<unsigned int> gridIndices = {
0,
1,
2,
2,
3,
0
};
std::vector<float> vertices = {
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
};
std::vector<unsigned int> indices = {
0,
1,
2,
2,
3,
0,
4,
5,
6,
6,
7,
4,
0,
1,
5,
5,
4,
0,
3,
2,
6,
6,
7,
3,
0,
3,
7,
7,
4,
0,
1,
2,
6,
6,
5,
1,
};
Archimedes::Body readOBJ(std::string path, Archimedes::Shader shader) {
std::ifstream file(path);
if(!file.is_open()) return Archimedes::Body();
std::string s;
std::vector<float> verticies;
std::vector<unsigned int> indicies;
verticies.reserve(3 * 100);
indicies.reserve(100);
unsigned int i = 0;
unsigned int j = 0;
float point;
unsigned int idx;
while(!file.eof()) {
getline(file, s, ' ');
//std::cout << "\nline start: " << s << std::endl;
if(s == "v") {
file >> point;
verticies.push_back(point);
//std::cout << "point1: " << point << std::endl;
file >> point;
verticies.push_back(point);
//std::cout << "point2: " << point << std::endl;
file >> point;
verticies.push_back(point);
//std::cout << "point3: " << point << std::endl;
//std::cout << "index: " << j << std::endl;
getline(file, s);
//file.ignore();
} else if(s == "f") {
file >> idx;
indicies.push_back(--idx);
file.ignore(5, ' ');
file >> idx;
indicies.push_back(--idx);
file.ignore(5, ' ');
file >> idx;
indicies.push_back(--idx);
getline(file, s);
} else {
getline(file, s);
}
}
file.close();
return Archimedes::Body(
Archimedes::VertexBuffer(verticies),
Archimedes::IndexArray(indicies),
Archimedes::VertexLayout({
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 3 * sizeof(float), 0),
}),
shader
);
}
};
#ifdef SANDBOX_DYNAMIC
typedef Sandbox mtype;
#include "endModule.h"
#endif
#endif

View File

@@ -0,0 +1,58 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.Sandbox = pkgs.stdenvNoCC.mkDerivation {
name = "Sandbox";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
curl
nlohmann_json
stb
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Sandbox/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-DSANDBOX_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,56 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.Terminal = pkgs.stdenvNoCC.mkDerivation {
name = "Terminal";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
curl
glm
nlohmann_json
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/Terminal/*.cpp \
modules/ImguiModule/*.cpp \
modules/WindowModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-DTERMINAL_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,38 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.TestClay = pkgs.stdenvNoCC.mkDerivation {
name = "TestClay";
src = inputs.src;
clay = inputs.clay;
nativeBuildInputs = with pkgs; [
clang
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestClay/*.cpp \
-fpic -shared \
-I include \
-DRENDERER=1 \
-DWINDOW=1 \
-DTESTCLAY_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,50 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.TestImgui = pkgs.stdenvNoCC.mkDerivation {
name = "TestImgui";
src = inputs.src;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestImgui/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DTESTIMGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -17,7 +17,7 @@ void TestNotCurses::onLoad() {
ncInstance = notcurses_init(&opts, NULL);
if(!ncInstance) {
app->stopModule(getName());
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return;
}
}

View File

@@ -0,0 +1,39 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.TestNotCurses = pkgs.stdenvNoCC.mkDerivation {
name = "TestNotCurses";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
notcurses
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestNotCurses/*.cpp \
-fpic -shared \
-I include \
-Wall \
-lnotcurses \
-DTESTNOTCURSES_DYNAMIC \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,67 @@
// This only works with opengl!!!!
#include "TestTriangle.h"
TestTriangle::TestTriangle(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "TestTriangle";
WindowModule* wm = new WindowModule(a, h);
deps[*wm] = wm;
}
TestTriangle::~TestTriangle() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
/*
#if WINDOW == 2
wm->removeEventFn(ecmd_it);
#endif
*/
wm->releaseWindow(window);
}
}
void TestTriangle::onLoad() {
// get window
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
if(!wm) {
std::cout << "No WindowModule TestTriangle!\n";
std::abort();
}
window = wm->aquireWindow();
window->getRenderer()->clearColor = { 0.2, 0.2, 0.4, 0.7 };
shader = Archimedes::Shader(vertexShaderSource, fragmentShaderSource, Archimedes::Shader::LoadType::FromSource);
window->getRenderer()->useShader(shader);
rt = Archimedes::RenderTarget(
Archimedes::VertexBuffer(vertices, 9 * sizeof(float)),
Archimedes::IndexArray(indices, 3),
Archimedes::VertexLayout(),
shader
);
window->getRenderer()->useRenderTarget(rt);
}
void TestTriangle::run() {
window->getRenderer()->draw(rt);
}
bool TestTriangle::onEvent(const Archimedes::Event& e) {
return false;
}

View File

@@ -0,0 +1,64 @@
// This only works with opengl!!!!
#include "Archimedes.h"
#include "modules/WindowModule/WindowModule.h"
#define GLEW_STATIC
#include <GL/glew.h>
class TestTriangle : public Archimedes::Module {
public:
TestTriangle(Archimedes::App*, void*);
TestTriangle() { name = "TestTriangle"; }
~TestTriangle();
void onLoad() override;
void run() override;
bool onEvent(const Archimedes::Event& e) override;
private:
Archimedes::Window* window;
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main()\n"
"{\n"
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\n\0";
Archimedes::RenderTarget rt;
Archimedes::Shader shader;
float vertices[9] = {
-0.5f, -0.5f, 0.0f, // left
0.5f, -0.5f, 0.0f, // right
0.0f, 0.5f, 0.0f // top
};
unsigned int indices[3] = {
0, // left
1, // right
2 // top
};
};
#ifdef TESTTRIANGLE_DYNAMIC
typedef TestTriangle mtype;
#include "endModule.h"
#endif

View File

@@ -0,0 +1,48 @@
{ inputs, ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.TestTriangle = pkgs.stdenvNoCC.mkDerivation {
name = "TestTriangle";
src = inputs.src;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-DTESTTRIANGLE_DYNAMIC \
-fpic -shared \
-I include -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,40 @@
{ ... }: {
perSystem = { system, pkgs, self', ... }: {
packages.ClientModule = pkgs.stdenvNoCC.mkDerivation {
name = "ClientModule";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
gamenetworkingsockets
];
buildPhase = ''
clang++ \
modules/ClientModule/*.cpp \
-fpic -shared \
-I include \
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
-lGameNetworkingSockets \
-DCLIENTMODULE_DYNAMIC \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
}

View File

@@ -0,0 +1,140 @@
#include "ImguiModule.h"
#include "pch.hpp"
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
name = "ImguiModule";
WindowModule* wm = new WindowModule(a, h);
deps[*wm] = wm;
}
ImguiModule::~ImguiModule() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
#ifdef WINDOW_SDL3
wm->removeEventFn(ecmd_it);
#endif
rendererShutdown();
windowShutdown();
ImGui::DestroyContext();
wm->releaseWindow(window);
}
}
void ImguiModule::onLoad() {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
if(!wm) {
std::cout << "No WindowModule for ImguiModule!\n";
std::abort();
}
window = (Archimedes::WindowGLFW*) wm->aquireWindow();
#ifdef RENDERER_SDL3
renderer = window->getRenderer()->getRendererImpl()->renderer;
#endif
IMGUI_CHECKVERSION();
context = ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
#ifdef CUSTOMFONT
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
#endif
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup scaling
ImGuiStyle& style = ImGui::GetStyle();
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
// Setup Platform/Renderer backends
if(!windowInit())
std::cout << "windowInit failed\n";
if(!rendererInit()) {
std::cout << "rendererInit failed!\n" << std::endl;
}
#ifdef WINDOW_SDL3
ecmd_it = wm->addEventFn([](Archimedes::Event* e){
if(e->userData.type() == typeid(SDL_Event*)) {
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e->userData));
}
});
#endif
//Compute first frame ahead of first WindowModule->run()
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
void ImguiModule::run() {
ImGui::Render();
rendererRenderDrawData();
if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
window->getWindowImpl()->restoreContext();
}
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
};
bool ImguiModule::onEvent(const Archimedes::Event &e) {
unsigned int type = app->getEventType(e);
ImGuiIO& io = ImGui::GetIO(); (void)io;
if(type == app->getEventType(Archimedes::KeyPressedWindowEvent())) {
return io.WantCaptureKeyboard;
} else if(type == app->getEventType(Archimedes::KeyReleasedWindowEvent())) {
return io.WantCaptureKeyboard;
} else if(type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())) {
return io.WantCaptureMouse;
} else if(type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())) {
return io.WantCaptureMouse;
} else if(type == app->getEventType(Archimedes::ScrollWindowEvent())) {
return io.WantCaptureMouse;
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent())) {
return io.WantCaptureMouse;
}
return false;
}

Some files were not shown because too many files have changed in this diff Show More