Compare commits

...

27 Commits

Author SHA1 Message Date
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
30 changed files with 601 additions and 165 deletions

8
.ccls Normal file
View File

@@ -0,0 +1,8 @@
clang++
-Iinclude
-I.
-Ivendor/imgui
-Ivendor/notcurses/include
-Ivendor/GameNetworkingSockets/include
-DWINDOW=1
-DRENDERER=1

3
.gitignore vendored
View File

@@ -1 +1,2 @@
vendor/*
vendor/
.ccls-cache/

View File

@@ -11,14 +11,11 @@
nativeBuildInputs = with pkgs; [
clang
];
/*buildInputs = with pkgs; [
];*/
buildPhase = ''
clang++ \
src/example_apps/MinimalApp/MinimalApp.cpp \
-I src -I include \
-I include \
-Wall \
-o $name
'';
@@ -54,7 +51,7 @@
buildPhase = ''
clang++ \
src/example_apps/ImguiEmbed/*.cpp \
modules/Archimedes-Modules/TestImgui/*.cpp \
modules/MainGUI/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
@@ -64,7 +61,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lEGL -lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -106,7 +103,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';

View File

@@ -140,6 +140,76 @@
};
TestTrianglesdl = pkgs.stdenvNoCC.mkDerivation {
name = "TestTriangle";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
sdl3
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER=1 \
-DWINDOW=2 \
-DTESTTRIANGLE_DYNAMIC \
-fpic -shared \
-I include -I . \
-lEGL -lSDL3 -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestTriangle = pkgs.stdenvNoCC.mkDerivation {
name = "TestTriangle";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER=1 \
-DWINDOW=1 \
-DTESTTRIANGLE_DYNAMIC \
-fpic -shared \
-I include -I . \
-lEGL -lglfw -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestImgui = pkgs.stdenvNoCC.mkDerivation {
name = "TestImgui";

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

@@ -35,11 +35,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1769900590,
"narHash": "sha256-I7Lmgj3owOTBGuauy9FL6qdpeK2umDoe07lM4V+PnyA=",
"lastModified": 1770136044,
"narHash": "sha256-tlFqNG/uzz2++aAmn4v8J0vAkV3z7XngeIIB3rM3650=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "41e216c0ca66c83b12ab7a98cc326b5db01db646",
"rev": "e576e3c9cf9bad747afcddd9e34f51d18c855b4e",
"type": "github"
},
"original": {
@@ -49,11 +49,28 @@
"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",
"imgui": "imgui",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"nixpkgs-old": "nixpkgs-old"
}
}
},

41
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;
@@ -15,15 +16,17 @@
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
pkgs-old = import inputs.nixpkgs-old { inherit system; };
viewport-overlay = final: prev: { glfw = pkgs-old.glfw; };
pkgs = import nixpkgs { inherit system; overlays = [ viewport-overlay ]; };
in {
Archimedes = {
examples = import ./ExampleApps.nix { inherit inputs; inherit pkgs; };
examples = import ./ExampleApps.nix { inherit inputs pkgs; };
};
Modules = {
examples = import ./ExampleModules.nix { inherit inputs; inherit pkgs; };
examples = import ./ExampleModules.nix { inherit inputs pkgs; };
ServerModule = pkgs.stdenvNoCC.mkDerivation {
@@ -114,7 +117,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-DWINDOWMODULE_DYNAMIC \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -157,7 +160,7 @@
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -243,7 +246,7 @@
-DMAINGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -264,5 +267,31 @@
program = "${self.Archimedes.examples.MinimalApp}/bin/Archimedes";
};
devShells.${system} = {
default = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
'';
};
};
};
}

8
include/extratools.h Normal file
View File

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

View File

@@ -17,6 +17,7 @@
#include <optional>
#include <chrono>
//#include <thread>
#include <concepts>
#include <dlfcn.h>

View File

@@ -0,0 +1,22 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "pch.hpp"
#include "extratools.h"
namespace Archimedes {
class Object {
public:
Object() {};
~Object() {};
private:
};
}
#endif

View File

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

View File

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

View File

@@ -1,5 +1,3 @@
#if RENDERER == 2
#ifndef RENDERER_SDL3
#define RENDERER_SDL3
@@ -38,12 +36,6 @@ namespace Archimedes {
SDL_Renderer* renderer = nullptr;
};
typedef RendererSDL3 RendererImpl;
}
#endif
#endif

View File

@@ -0,0 +1,21 @@
#ifndef RENDERER_CONCEPTS
#define RENDERER_CONCEPTS
#include "pch.hpp"
namespace Archimedes {
class RendererOpenGL;
class RendererSDL3;
template <class RendererImpl>
concept allowed_renderers = requires (RendererImpl r) {
#ifndef CUSTOM_RENDERER
requires std::same_as<RendererImpl, RendererOpenGL>
|| std::same_as<RendererImpl, RendererSDL3>;
#endif
};
}
#endif

View File

@@ -4,8 +4,6 @@
#include "WindowEvents.h"
#include "utils/Renderer/Renderer.h"
#include "WindowGLFW/WindowGLFW.h"
#include "WindowSDL3/WindowSDL3.h"
namespace Archimedes {
@@ -13,34 +11,44 @@ namespace Archimedes {
public:
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {}
Window(const std::function<void(Event*)>& sendEventFn) : eventFn(sendEventFn) {}
~Window() {}
virtual ~Window() = 0;
bool shouldClose() { return window.shouldClose(); }
void getSize(int& w, int& h) {
window.getSize(w, h);
}
void doFrame() {
renderer->render();
window.doFrame();
swapBuffers();
pollEvents();
window.pollEvents();
}
virtual bool shouldClose() = 0;
virtual void swapBuffers() = 0;
virtual void pollEvents() = 0;
virtual void getSize(int& w, int& h) {
w = this->w;
h = this->h;
}
Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) { renderer = r; }
WindowImpl& getWindowImpl() { return window; }
virtual Window* getWindowImpl() = 0;
protected:
int w, h;
private:
Renderer* renderer;
WindowImpl window;
std::function<void(Event*)> eventFn;
};
}

View File

@@ -5,7 +5,7 @@
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
@@ -13,20 +13,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 +30,36 @@ namespace Archimedes {
std::cout << "glfwInit failed!\n";
std::abort();
}
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
#if RENDRER == 1
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
window = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!w) {
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 +75,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 +88,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,31 +106,31 @@ 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 restoreContext() { glfwMakeContextCurrent(window); }
void pollEvents() { glfwPollEvents(); }
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
void getSize(int& w, int& h) override {
glfwGetFramebufferSize(window, &w, &h);
}
GLFWwindow* getWindow() { return w; }
GLFWwindow* getWindow() { return window; }
WindowData data;
virtual WindowGLFW* getWindowImpl() override { return this; }
private:
GLFWwindow* w;
GLFWwindow* window;
};
typedef WindowGLFW WindowImpl;
}
#endif

View File

@@ -5,7 +5,7 @@
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#include <SDL3/SDL.h>
@@ -17,8 +17,6 @@
namespace Archimedes {
class Window;
static bool EventCallback(void* ptr, SDL_Event* e) {
WindowData& data = *(WindowData*) ptr;
@@ -66,13 +64,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)) {
@@ -90,16 +88,16 @@ namespace Archimedes {
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);
gl_context = SDL_GL_CreateContext(window);
if (gl_context == nullptr)
{
@@ -107,12 +105,12 @@ 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() {
@@ -120,52 +118,52 @@ namespace Archimedes {
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() {
void swapBuffers() override {
#if RENDERER == 1
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));
}
WindowSDL3* getWindowImpl() { return this; };
#if RENDERER == 1
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
void restoreContext() { SDL_GL_MakeCurrent(window, gl_context); }
#endif
void getSize(int& w, int& h) {
w = this->width;
h = this->height;
void getSize(int& w, int& h) override {
w = this->w;
h = this->h;
}
void setSize(int& w, int& h) {
this->width = w;
this->height = h;
this->w = w;
this->h = h;
}
SDL_Window* getWindow() { return w; }
SDL_Window* getWindow() { return window; }
#if RENDERER == 1
SDL_GLContext getContext() { return gl_context; }
#endif
WindowData data;
private:
SDL_Window* w;
int width = 0, height = 0;
SDL_Window* window;
#if RENDERER == 1
SDL_GLContext gl_context;
#endif
};
typedef WindowSDL3 WindowImpl;
}
#endif

View File

@@ -0,0 +1,25 @@
#ifndef WINDOW_CONCEPTS
#define WINDOW_CONCEPTS
#include "pch.hpp"
#include "utils/Renderer/concepts.h"
namespace Archimedes {
template <class R>
class WindowGLFW;
template <class R>
class WindowSDL3;
template <class WindowImpl, class R>
concept allowed_windows = requires (WindowImpl a, R b) {
#ifndef CUSTOM_WINDOW
requires std::same_as<WindowImpl, WindowGLFW<R>>
|| std::same_as<WindowImpl, WindowSDL3<R>>;
#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

@@ -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

@@ -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,139 @@
// 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()]; }
wm->getRenderer()->getCmdList().erase(rcmd_it);
/*
#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 for ImguiModule!\n";
std::abort();
}
window = wm->aquireWindow();
wm->getRenderer()->getCmdList().push_back([this](){
// draw our first triangle
glUseProgram(shaderProgram);
glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0); // no need to unbind it every time
});
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
//////////////////////glew
/*
if(glewInit() != GLEW_OK) {
std::cout << "glew is not ok!" << std::endl;
std::abort();
}
*/
///////////////////////////////NUCLEAR
// build and compile our shader program
// ------------------------------------
// vertex shader
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, 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, &fragmentShaderSource, 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
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);
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other
// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.
glBindVertexArray(0);
// uncomment this call to draw in wireframe polygons.
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
void TestTriangle::run() {
}
bool TestTriangle::onEvent(const Archimedes::Event& e) {
return false;
}

View File

@@ -0,0 +1,60 @@
// 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;
std::list<std::function<void()>>::iterator rcmd_it;
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";
unsigned int shaderProgram;
unsigned int VBO, VAO;
float vertices[9] = {
-0.5f, -0.5f, 0.0f, // left
0.5f, -0.5f, 0.0f, // right
0.0f, 0.5f, 0.0f // top
};
};
#ifdef TESTTRIANGLE_DYNAMIC
typedef TestTriangle mtype;
#include "endModule.h"
#endif

View File

@@ -51,8 +51,8 @@ void ImguiModule::onLoad() {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
#ifdef CUSTOMFONT
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
#endif
@@ -60,6 +60,18 @@ void ImguiModule::onLoad() {
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";
@@ -73,9 +85,12 @@ void ImguiModule::onLoad() {
rendererRenderDrawData();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
window->getWindowImpl().restoreContext();
}
});
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
@@ -92,30 +107,15 @@ void ImguiModule::onLoad() {
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
void ImguiModule::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

@@ -38,6 +38,8 @@ class ImguiModule : public Archimedes::Module {
~ImguiModule();
void onLoad() override;
void run() override;
bool onEvent(const Archimedes::Event&) override;

View File

@@ -56,6 +56,8 @@ void MainGUI::run() {
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
ImGui::ShowDemoWindow();
} else {
app->end();
}

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);
};