Compare commits
16 Commits
cd19db0b88
...
8581589bfe
| Author | SHA1 | Date | |
|---|---|---|---|
| 8581589bfe | |||
| 9dfabc6dae | |||
| 3f102638b0 | |||
| 5ab345460c | |||
| e67df40233 | |||
| 07b4518cb4 | |||
| 43d950b035 | |||
| 78a8c9bf95 | |||
| 7a45547ad9 | |||
| 21080c5c63 | |||
| 68524696df | |||
| 8c0cba9397 | |||
| afe6254317 | |||
| e38a83e521 | |||
| 7517ee8593 | |||
| 148ed1253c |
8
.ccls
Normal file
8
.ccls
Normal file
@@ -0,0 +1,8 @@
|
||||
clang++
|
||||
-Iinclude
|
||||
-I.
|
||||
-Ivendor/imgui
|
||||
-Ivendor/notcurses/include
|
||||
-Ivendor/GameNetworkingSockets/include
|
||||
-DWINDOW=1
|
||||
-DRENDERER=1
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
vendor/*
|
||||
vendor/
|
||||
.ccls-cache/
|
||||
|
||||
@@ -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 \
|
||||
-lGL -lEGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
@@ -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
6
flake.lock
generated
@@ -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": {
|
||||
|
||||
25
flake.nix
25
flake.nix
@@ -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 = ''
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -17,7 +17,7 @@ void TestNotCurses::onLoad() {
|
||||
ncInstance = notcurses_init(&opts, NULL);
|
||||
|
||||
if(!ncInstance) {
|
||||
app->stopModule(getName());
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
139
modules/Archimedes-Modules/TestTriangle/TestTriangle.cpp
Normal file
139
modules/Archimedes-Modules/TestTriangle/TestTriangle.cpp
Normal 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;
|
||||
}
|
||||
60
modules/Archimedes-Modules/TestTriangle/TestTriangle.h
Normal file
60
modules/Archimedes-Modules/TestTriangle/TestTriangle.h
Normal 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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user