Compare commits

...

16 Commits

Author SHA1 Message Date
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
15 changed files with 368 additions and 43 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

@@ -12,13 +12,10 @@
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 \
-lGL -lEGL -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";

6
flake.lock generated
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": {

View File

@@ -264,5 +264,30 @@
program = "${self.Archimedes.examples.MinimalApp}/bin/Archimedes";
};
devShells.${system} = {
default = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
nlohmann_json
gamenetworkingsockets
];
shellHook = ''
'';
};
};
};
}

View File

@@ -26,7 +26,7 @@ namespace Archimedes {
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)

View File

@@ -37,6 +37,11 @@ namespace Archimedes {
std::cout << "glfwInit failed!\n";
std::abort();
}
#if RENDRER == 1
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!w) {

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,7 +51,7 @@ 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);
@@ -96,26 +96,6 @@ void ImguiModule::onLoad() {
}
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);
};