Compare commits
8 Commits
f75a438422
...
3b27c2fb06
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b27c2fb06 | |||
| f7f487bb9c | |||
| 9035f6c3ae | |||
| 4d31a85d2d | |||
| c04fb4e330 | |||
| 18c12157dd | |||
| 788f242c47 | |||
| a8f55d2ebe |
71
src/example_apps/RubiksApp/RubiksApp.cpp
Normal file
71
src/example_apps/RubiksApp/RubiksApp.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "RubiksApp.h"
|
||||
|
||||
bool RubiksApp::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 RubiksApp::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();
|
||||
}
|
||||
}
|
||||
29
src/example_apps/RubiksApp/RubiksApp.h
Normal file
29
src/example_apps/RubiksApp/RubiksApp.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/Archimedes-Modules/Rubiks/Rubiks.h"
|
||||
|
||||
class RubiksApp : public Archimedes::App {
|
||||
|
||||
private:
|
||||
|
||||
void printHelp() override {};
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
public:
|
||||
RubiksApp() {
|
||||
Archimedes::Module* m = (Archimedes::Module*) new Rubiks(Get(), nullptr);
|
||||
|
||||
load(m);
|
||||
};
|
||||
~RubiksApp() {};
|
||||
|
||||
void handleArgs(const int& argc, char* argv[]) override {};
|
||||
|
||||
void run() override;
|
||||
|
||||
};
|
||||
|
||||
#define APP_TYPE RubiksApp
|
||||
#include "endApp.h"
|
||||
56
src/example_apps/RubiksApp/default.nix
Normal file
56
src/example_apps/RubiksApp/default.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.exampleApps_RubiksApp = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Rubiks";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
nlohmann_json
|
||||
curl
|
||||
|
||||
stb
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
example_apps/RubiksApp/*.cpp \
|
||||
modules/Archimedes-Modules/Rubiks/*.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
|
||||
'';
|
||||
|
||||
}; };
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "utils/Renderer/RenderTarget.h"
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
27
src/include/utils/Objects/Light.h
Normal file
27
src/include/utils/Objects/Light.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Light : public Object {
|
||||
|
||||
public:
|
||||
Light(glm::mat4 t = glm::mat4(1.0f), float a = 2 * glm::pi<float>()) : Object(t), angle(a) {};
|
||||
|
||||
Light() : Object(glm::mat4(1.0f)), angle(2 * glm::pi<float>()) {}
|
||||
|
||||
~Light() {};
|
||||
|
||||
private:
|
||||
|
||||
float angle;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "utils/Renderer/RenderTarget.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace Archimedes {
|
||||
|
||||
class LayoutElement {
|
||||
|
||||
friend class VertexLayout;
|
||||
|
||||
public:
|
||||
|
||||
enum class Type {
|
||||
@@ -54,8 +56,25 @@ namespace Archimedes {
|
||||
Double
|
||||
};
|
||||
|
||||
LayoutElement(Type type, size_t count, size_t stride, size_t offset)
|
||||
: type(type), count(count), stride(stride), offset(offset) {}
|
||||
LayoutElement(Type type, size_t count)
|
||||
: type(type), count(count), size(count) {
|
||||
switch(type) {
|
||||
case Type::Float:
|
||||
size *= sizeof(float);
|
||||
break;
|
||||
case Type::UInt:
|
||||
size *= sizeof(unsigned int);
|
||||
break;
|
||||
case Type::Int:
|
||||
size *= sizeof(int);
|
||||
break;
|
||||
case Type::Double:
|
||||
size *= sizeof(double);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
~LayoutElement() {}
|
||||
|
||||
@@ -63,16 +82,11 @@ namespace Archimedes {
|
||||
|
||||
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;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
class VertexLayout {
|
||||
@@ -84,6 +98,25 @@ namespace Archimedes {
|
||||
|
||||
std::vector<LayoutElement>& getElements() { return elements; }
|
||||
|
||||
size_t getStride() {
|
||||
size_t stride = 0;
|
||||
for(LayoutElement& e : elements) {
|
||||
stride += e.size;
|
||||
}
|
||||
return stride;
|
||||
}
|
||||
|
||||
size_t getElementOffset(unsigned int idx) {
|
||||
if(idx < 0 || idx >= elements.size()) {
|
||||
return 0;
|
||||
}
|
||||
size_t offset = 0;
|
||||
for(unsigned int i = 0; i < idx; i++) {
|
||||
offset += elements.at(i).size;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<LayoutElement> elements;
|
||||
};
|
||||
@@ -256,7 +289,11 @@ namespace Archimedes {
|
||||
|
||||
std::vector<unsigned char> s;
|
||||
|
||||
s.reserve(10000);
|
||||
file.seekg(std::ios::end);
|
||||
|
||||
s.reserve(file.tellg());
|
||||
|
||||
file.seekg(std::ios::beg);
|
||||
|
||||
while(!file.eof()) {
|
||||
s.push_back(file.get());
|
||||
|
||||
@@ -156,31 +156,30 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
|
||||
unsigned int i = 0;
|
||||
for(LayoutElement e : rt.layout.getElements()) {
|
||||
for(unsigned int i = 0; i < rt.layout.getElements().size(); i++) {
|
||||
|
||||
LayoutElement& e = rt.layout.getElements().at(i);
|
||||
|
||||
switch(e.getType()) {
|
||||
case LayoutElement::Type::Float:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_FLOAT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glVertexAttribPointer(i, e.getCount(), GL_FLOAT, GL_FALSE, rt.layout.getStride(), (void*)rt.layout.getElementOffset(i));
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::Double:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_DOUBLE, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glVertexAttribPointer(i, e.getCount(), GL_DOUBLE, GL_FALSE, rt.layout.getStride(), (void*)rt.layout.getElementOffset(i));
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::Int:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glVertexAttribPointer(i, e.getCount(), GL_INT, GL_FALSE, rt.layout.getStride(), (void*)rt.layout.getElementOffset(i));
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::UInt:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_UNSIGNED_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glVertexAttribPointer(i, e.getCount(), GL_UNSIGNED_INT, GL_FALSE, rt.layout.getStride(), (void*)rt.layout.getElementOffset(i));
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
195
src/modules/Archimedes-Modules/Rubiks/Rubiks.cpp
Normal file
195
src/modules/Archimedes-Modules/Rubiks/Rubiks.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
// This only works with opengl!!!!
|
||||
|
||||
|
||||
#include "Rubiks.h"
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb/stb_truetype.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
Rubiks::Rubiks(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Rubiks";
|
||||
|
||||
WindowModule* wm = new WindowModule(a, h);
|
||||
deps[*wm] = wm;
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Rubiks::~Rubiks() {
|
||||
|
||||
if(app) {
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
|
||||
wm->releaseWindow(window);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Rubiks::onLoad() {
|
||||
// get window
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!wm) {
|
||||
std::cout << "No WindowModule for Rubiks!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Rubiks!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
window = wm->aquireWindow();
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
window->getRenderer()->clearColor = { 0, 0, 0, 1.0f };
|
||||
|
||||
|
||||
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());
|
||||
|
||||
int w, h;
|
||||
window->getSize(w, h);
|
||||
app->emitEvent(new Archimedes::ResizeWindowEvent(w, h));
|
||||
|
||||
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 Rubiks::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;
|
||||
|
||||
window->getRenderer()->draw(
|
||||
cube.getMesh(),
|
||||
cube.getTransform(),
|
||||
camera.getTransform(),
|
||||
camera.getPerspective(),
|
||||
color
|
||||
);
|
||||
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
static glm::vec4& clearColor = window->getRenderer()->clearColor;
|
||||
|
||||
ImGui::Begin("Rubiks 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);
|
||||
|
||||
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 Rubiks::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));
|
||||
|
||||
return true;
|
||||
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent()) && !io.WantCaptureMouse) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
178
src/modules/Archimedes-Modules/Rubiks/Rubiks.h
Normal file
178
src/modules/Archimedes-Modules/Rubiks/Rubiks.h
Normal file
@@ -0,0 +1,178 @@
|
||||
// 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"
|
||||
|
||||
class Rubiks : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Rubiks(Archimedes::App*, void*);
|
||||
|
||||
Rubiks() { name = "Rubiks"; }
|
||||
|
||||
~Rubiks();
|
||||
|
||||
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"
|
||||
"layout (location = 1) in vec3 aNorm;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform mat4 view;\n"
|
||||
"uniform mat4 proj;\n"
|
||||
"uniform vec4 color;\n"
|
||||
"out vec3 Norm;\n"
|
||||
"out vec3 FragPos;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = proj * view * model * vec4(aPos, 1.0f);\n"
|
||||
" Norm = mat3(transpose(inverse(model))) * aNorm;\n"
|
||||
" FragPos = vec3(model * vec4(aPos, 1.0f));\n"
|
||||
"}\0";
|
||||
|
||||
std::string cubeFS = "#version 430 core\n"
|
||||
"in vec3 Norm;\n"
|
||||
"in vec3 FragPos;\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"
|
||||
" vec3 light = vec3(1.0f, 1.0f, 1.0f);\n"
|
||||
" vec3 amblight = 0.1f * light;\n"
|
||||
" vec3 norm = normalize(Norm);\n"
|
||||
" vec3 lightdir = normalize(vec3(-10, 20, 20) - FragPos);\n"
|
||||
" vec3 diff = max(dot(norm, lightdir), 0.0) * light;\n"
|
||||
" FragColor = vec4((amblight + diff) * color.rgb, 1.0f);\n"
|
||||
"}\n\0";
|
||||
|
||||
Archimedes::Shader cubeShader;
|
||||
Archimedes::Body cube;
|
||||
|
||||
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3),
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3)
|
||||
});
|
||||
|
||||
Archimedes::Camera camera;
|
||||
|
||||
std::vector<float> vertices = {
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
std::vector<unsigned int> indices = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
|
||||
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
|
||||
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
|
||||
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
|
||||
|
||||
24,
|
||||
25,
|
||||
26,
|
||||
27,
|
||||
28,
|
||||
29,
|
||||
|
||||
|
||||
30,
|
||||
31,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#ifdef SANDBOX_DYNAMIC
|
||||
typedef Rubiks mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
58
src/modules/Archimedes-Modules/Rubiks/default.nix
Normal file
58
src/modules/Archimedes-Modules/Rubiks/default.nix
Normal file
@@ -0,0 +1,58 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Rubiks = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Rubiks";
|
||||
|
||||
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/Rubiks/*.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
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -165,8 +165,8 @@ namespace Archimedes {
|
||||
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))
|
||||
LayoutElement(LayoutElement::Type::Float, 3),
|
||||
LayoutElement(LayoutElement::Type::Float, 2)
|
||||
}),
|
||||
shader,
|
||||
texture,
|
||||
@@ -437,7 +437,7 @@ namespace Archimedes {
|
||||
private:
|
||||
|
||||
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3)
|
||||
});
|
||||
|
||||
std::unordered_map<std::string, Body> templateMap;
|
||||
|
||||
@@ -60,7 +60,7 @@ class Sandbox : public Archimedes::Module {
|
||||
Archimedes::Body cube, grid, hexagon;
|
||||
|
||||
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3)
|
||||
});
|
||||
|
||||
Archimedes::Camera camera;
|
||||
@@ -212,7 +212,7 @@ Archimedes::Body readOBJ(std::string path, Archimedes::Shader shader) {
|
||||
Archimedes::VertexBuffer(verticies),
|
||||
Archimedes::IndexArray(indicies),
|
||||
Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 3 * sizeof(float), 0),
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3),
|
||||
}),
|
||||
shader
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user