work on TestTriangle
This commit is contained in:
@@ -51,7 +51,7 @@
|
|||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
clang++ \
|
clang++ \
|
||||||
src/example_apps/ImguiEmbed/*.cpp \
|
src/example_apps/ImguiEmbed/*.cpp \
|
||||||
modules/Archimedes-Modules/TestImgui/*.cpp \
|
modules/MainGUI/*.cpp \
|
||||||
modules/WindowModule/*.cpp \
|
modules/WindowModule/*.cpp \
|
||||||
modules/ImguiModule/*.cpp \
|
modules/ImguiModule/*.cpp \
|
||||||
$imgui/backends/imgui_impl_glfw.cpp \
|
$imgui/backends/imgui_impl_glfw.cpp \
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
-DRENDERER=1 \
|
-DRENDERER=1 \
|
||||||
-DWINDOW=1 \
|
-DWINDOW=1 \
|
||||||
-I include -I $imgui -I . \
|
-I include -I $imgui -I . \
|
||||||
-lEGL -lglfw -lGLEW \
|
-lGL -lEGL -lglfw -lGLEW \
|
||||||
-Wall \
|
-Wall \
|
||||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -158,7 +158,6 @@
|
|||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
clang++ \
|
clang++ \
|
||||||
modules/Archimedes-Modules/TestTriangle/*.cpp \
|
modules/Archimedes-Modules/TestTriangle/*.cpp \
|
||||||
modules/WindowModule/*.cpp \
|
|
||||||
-DRENDERER=1 \
|
-DRENDERER=1 \
|
||||||
-DWINDOW=1 \
|
-DWINDOW=1 \
|
||||||
-DTESTTRIANGLE_DYNAMIC \
|
-DTESTTRIANGLE_DYNAMIC \
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ namespace Archimedes {
|
|||||||
std::cout << "glfwInit failed!\n";
|
std::cout << "glfwInit failed!\n";
|
||||||
std::abort();
|
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);
|
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
|
||||||
|
|
||||||
if(!w) {
|
if(!w) {
|
||||||
|
|||||||
@@ -1,70 +1,132 @@
|
|||||||
#include "TestTriangle.h"
|
#include "TestTriangle.h"
|
||||||
#include "modules/WindowModule/WindowModule.h"
|
|
||||||
|
|
||||||
#define GLEW_STATIC
|
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
TestTriangle::TestTriangle(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
TestTriangle::TestTriangle(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||||
|
|
||||||
name = "TestTriangle";
|
name = "TestTriangle";
|
||||||
|
|
||||||
WindowModule* wm = new WindowModule(a, h);
|
|
||||||
deps[*wm] = wm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTriangle::~TestTriangle() {
|
TestTriangle::~TestTriangle() {
|
||||||
|
|
||||||
if(app) {
|
if(app) {
|
||||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
app->unregisterEvent(Archimedes::ResizeWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::CloseWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::KeyPressedWindowEvent());
|
||||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
app->unregisterEvent(Archimedes::KeyReleasedWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::MouseButtonPressedWindowEvent());
|
||||||
wm->releaseWindow(window);
|
app->unregisterEvent(Archimedes::MouseButtonReleasedWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::ScrollWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::MouseMovedWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::FocusedWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::FocusLostWindowEvent());
|
||||||
|
app->unregisterEvent(Archimedes::MovedWindowEvent());
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestTriangle::onLoad() {
|
void TestTriangle::onLoad() {
|
||||||
|
////////////////////////////register events
|
||||||
|
app->registerEvent(Archimedes::ResizeWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::CloseWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::KeyPressedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::KeyReleasedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::MouseButtonPressedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::MouseButtonReleasedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::ScrollWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::MouseMovedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::FocusedWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::FocusLostWindowEvent());
|
||||||
|
app->registerEvent(Archimedes::MovedWindowEvent());
|
||||||
|
//////////////////////glfw
|
||||||
|
|
||||||
|
std::cout << "events registered" << std::endl;
|
||||||
|
|
||||||
|
data.window = nullptr;
|
||||||
|
data.sendEvent = [this](Archimedes::Event* e) {
|
||||||
|
app->emitEvent(e);
|
||||||
|
};
|
||||||
|
glfwSetErrorCallback([](int e, const char* m){
|
||||||
|
std::cout << "GLFW Error " << e << ": " << m << std::endl;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!glfwInit()) {
|
||||||
|
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) {
|
||||||
|
std::cout << "glfwCreateWindow failed!\n";
|
||||||
|
glfwTerminate();
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
glfwMakeContextCurrent(w);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwSetWindowUserPointer(w, &data);
|
||||||
|
|
||||||
|
glfwSetWindowSizeCallback(w, [](GLFWwindow* window, int w, int h){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
d.sendEvent(new Archimedes::ResizeWindowEvent(w, h));
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSetWindowCloseCallback(w, [](GLFWwindow* window){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
d.sendEvent(new Archimedes::CloseWindowEvent(d.window));
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSetKeyCallback(w, [](GLFWwindow* window, int key, int scancode, int action, int mods){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
switch(action) {
|
||||||
|
case GLFW_PRESS:
|
||||||
|
d.sendEvent(new Archimedes::KeyPressedWindowEvent(key, 0));
|
||||||
|
break;
|
||||||
|
case GLFW_RELEASE:
|
||||||
|
d.sendEvent(new Archimedes::KeyReleasedWindowEvent(key));
|
||||||
|
break;
|
||||||
|
case GLFW_REPEAT:
|
||||||
|
d.sendEvent(new Archimedes::KeyPressedWindowEvent(key, 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSetMouseButtonCallback(w, [](GLFWwindow* window, int button, int action, int mods){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
switch(action) {
|
||||||
|
case GLFW_PRESS:
|
||||||
|
d.sendEvent(new Archimedes::MouseButtonPressedWindowEvent(button));
|
||||||
|
break;
|
||||||
|
case GLFW_RELEASE:
|
||||||
|
d.sendEvent(new Archimedes::MouseButtonReleasedWindowEvent(button));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSetScrollCallback(w, [](GLFWwindow* window, double dx, double dy){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
d.sendEvent(new Archimedes::ScrollWindowEvent(dx, dy));
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSetCursorPosCallback(w, [](GLFWwindow* window, double dx, double dy){
|
||||||
|
Archimedes::WindowData& d = *(Archimedes::WindowData*) glfwGetWindowUserPointer(window);
|
||||||
|
|
||||||
|
d.sendEvent(new Archimedes::MouseMovedWindowEvent(dx, dy));
|
||||||
|
});
|
||||||
|
|
||||||
|
//////////////////////gl
|
||||||
|
std::cout << "glfw setup" << std::endl;
|
||||||
|
|
||||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
|
||||||
|
|
||||||
if(!wm) {
|
|
||||||
std::cout << "No WindowModule for TestTriangle!\n";
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
window = wm->aquireWindow();
|
|
||||||
|
|
||||||
wm->getRenderer()->getCmdList().push_back([this](){
|
|
||||||
// 0. copy our vertices array in a buffer for OpenGL to use
|
|
||||||
//glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
// 1. then set the vertex attributes pointers
|
|
||||||
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
|
||||||
//glEnableVertexAttribArray(0);
|
|
||||||
// 2. use our shader program when we want to render an object
|
|
||||||
glUseProgram(program);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
// 3. now draw the object
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
||||||
//glBindVertexArray(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
|
||||||
|
|
||||||
////////////////////////
|
|
||||||
|
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
vs = glCreateShader(GL_VERTEX_SHADER);
|
vs = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(vs, 1, &vertexShaderSource, NULL);
|
glShaderSource(vs, 1, &vertexShaderSource, NULL);
|
||||||
glCompileShader(vs);
|
glCompileShader(vs);
|
||||||
@@ -101,12 +163,85 @@ void TestTriangle::onLoad() {
|
|||||||
std::cout << "shader linking failed!" << std::endl;
|
std::cout << "shader linking failed!" << std::endl;
|
||||||
std::abort();
|
std::abort();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::cout << "shader program complete" << std::endl;
|
||||||
|
|
||||||
glDeleteShader(vs);
|
glDeleteShader(vs);
|
||||||
glDeleteShader(fs);
|
glDeleteShader(fs);
|
||||||
|
|
||||||
|
std::cout << "shaders destroyed" << std::endl;
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo);
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "load success" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestTriangle::run() {
|
void TestTriangle::run() {
|
||||||
|
|
||||||
|
std::cout << "run" << std::endl;
|
||||||
|
glClearColor(0.2, 0.2, 0.4, 1);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glUseProgram(this->program);
|
||||||
|
glBindVertexArray(this->vao);
|
||||||
|
// 3. now draw the object
|
||||||
|
int f = 0, c = 3;
|
||||||
|
glMultiDrawArrays(GL_TRIANGLES, &f, &c, 1);
|
||||||
|
//glBindVertexArray(0);
|
||||||
|
|
||||||
|
glfwSwapBuffers(w);
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TestTriangle::onEvent(const Archimedes::Event& e) {
|
||||||
|
|
||||||
|
unsigned int type = app->getEventType(e);
|
||||||
|
|
||||||
|
if(type == app->getEventType(Archimedes::ResizeWindowEvent())) {
|
||||||
|
Archimedes::ResizeWindowEvent& event = (Archimedes::ResizeWindowEvent&) e;
|
||||||
|
glViewport(0, 0, event.width, event.height);
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::CloseWindowEvent())) {
|
||||||
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::KeyPressedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::KeyReleasedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::ScrollWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::FocusedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::FocusLostWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if(type == app->getEventType(Archimedes::MovedWindowEvent())) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
#include "modules/WindowModule/WindowModule.h"
|
#include "utils/Window/WindowEvents.h"
|
||||||
|
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
|
||||||
class TestTriangle : public Archimedes::Module {
|
class TestTriangle : public Archimedes::Module {
|
||||||
|
|
||||||
@@ -11,16 +17,17 @@ class TestTriangle : public Archimedes::Module {
|
|||||||
|
|
||||||
~TestTriangle();
|
~TestTriangle();
|
||||||
|
|
||||||
void onLoad();
|
void onLoad() override;
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
|
bool onEvent(const Archimedes::Event& e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
GLFWwindow* w;
|
||||||
|
|
||||||
Archimedes::Window* window;
|
Archimedes::WindowData data;
|
||||||
|
|
||||||
std::list<std::function<void()>>::iterator rcmd_it;
|
|
||||||
|
|
||||||
float vertices[3 * 3] = {
|
float vertices[3 * 3] = {
|
||||||
-0.5f, -0.5f, 0.0f,
|
-0.5f, -0.5f, 0.0f,
|
||||||
|
|||||||
@@ -1,31 +1,71 @@
|
|||||||
#include "ImguiEmbed.h"
|
#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() {
|
void ImguiEmbed::run() {
|
||||||
|
|
||||||
for(auto m : runOrder)
|
for(std::string m : runOrder) {
|
||||||
modules[m]->onLoad();
|
modules[m]->onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!done && !runOrder.empty()) {
|
while (!done && !runOrder.empty()) {
|
||||||
|
|
||||||
for(auto m : runOrder) {
|
for(std::string m : runOrder) {
|
||||||
modules[m]->run();
|
modules[m]->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto m : toClose) {
|
handleEvents();
|
||||||
|
|
||||||
|
for(std::string m : toClose) {
|
||||||
unload(m);
|
unload(m);
|
||||||
}
|
}
|
||||||
toClose.clear();
|
toClose.clear();
|
||||||
|
|
||||||
for(auto m : toOpen) {
|
for(auto m : toOpen) {
|
||||||
|
static Archimedes::Module* n;
|
||||||
if(std::holds_alternative<std::string>(m)) {
|
if(std::holds_alternative<std::string>(m)) {
|
||||||
load(std::get<std::string>(m))->onLoad();
|
n = load(std::get<std::string>(m));
|
||||||
} else {
|
} else {
|
||||||
load(std::get<Archimedes::Module*>(m))->onLoad();
|
n = load(std::get<Archimedes::Module*>(m));
|
||||||
|
}
|
||||||
|
if(n) {
|
||||||
|
n->onLoad();
|
||||||
|
n = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toOpen.clear();
|
toOpen.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#define ENTRYPOINT
|
#define ENTRYPOINT
|
||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
#include "modules/Archimedes-Modules/TestImgui/TestImgui.h"
|
#include "modules/MainGUI/MainGUI.h"
|
||||||
|
|
||||||
class ImguiEmbed : public Archimedes::App {
|
class ImguiEmbed : public Archimedes::App {
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class ImguiEmbed : public Archimedes::App {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ImguiEmbed() {
|
ImguiEmbed() {
|
||||||
Archimedes::Module* m = (Archimedes::Module*) new TestImgui(Get(), nullptr);
|
Archimedes::Module* m = (Archimedes::Module*) new MainGUI(Get(), nullptr);
|
||||||
|
|
||||||
load(m);
|
load(m);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user