the gui problem^TM
This commit is contained in:
@@ -1,5 +1,49 @@
|
|||||||
#include "TestImgui.h"
|
#include "TestImgui.h"
|
||||||
|
|
||||||
void TestImgui::load() {}
|
#include "imgui/imgui.h"
|
||||||
|
#include "imgui/backends/imgui_impl_glfw.h"
|
||||||
|
#include "imgui/backends/imgui_impl_opengl3.h"
|
||||||
|
|
||||||
void TestImgui::run() {}
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
TestImgui::TestImgui(void* h, Archimedes::App& a) : Archimedes::GuiModule(h, a) {
|
||||||
|
name = "TestImgui";
|
||||||
|
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||||
|
|
||||||
|
// Setup Dear ImGui style
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
// Setup Platform/Renderer backends
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(getWindow()->getWindowImpl().getWindow(), true);
|
||||||
|
ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestImgui::~TestImgui() {
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestImgui::onLoad() {}
|
||||||
|
|
||||||
|
void TestImgui::run() {
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
ImGui::ShowDemoWindow(&this->demo);
|
||||||
|
|
||||||
|
ImGui::Render();
|
||||||
|
|
||||||
|
getWindow()->getRenderer().addRenderCmd([](){
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,38 +1,24 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
#include <imgui.h>
|
|
||||||
#include <backends/imgui_impl_glfw.h>
|
|
||||||
#include <backends/imgui_impl_opengl3.h>
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
class TestImgui : public Archimedes::GuiModule {
|
||||||
|
|
||||||
class TestImgui : public Module {
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestImgui(void* h, App& a) : Module(h, a) {
|
TestImgui(void*, Archimedes::App&);
|
||||||
|
|
||||||
std::cout << "Enter path to Window library: ";
|
~TestImgui();
|
||||||
std::string path;
|
|
||||||
std::cin.ignore();
|
|
||||||
std::getline(std::cin, path);
|
|
||||||
|
|
||||||
deps["Window"] = path;
|
void onLoad();
|
||||||
name = "TestImgui";
|
|
||||||
}
|
|
||||||
|
|
||||||
~TestImgui() {}
|
|
||||||
|
|
||||||
void load();
|
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool demo = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Module* create(void* handle, App& app) {
|
Archimedes::Module* create(void* handle, Archimedes::App& app) {
|
||||||
return new TestImgui(handle, app);
|
return new TestImgui(handle, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
|
|
||||||
App* App::instance = nullptr;
|
Archimedes::App* Archimedes::App::instance = nullptr;
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
|
||||||
App::App(const int& argc, char* argv[]) {
|
App::App(const int& argc, char* argv[]) {
|
||||||
|
|
||||||
@@ -158,3 +161,4 @@ void App::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
#include "GuiModule.h"
|
#include "GuiModule.h"
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -45,4 +47,6 @@ class App {
|
|||||||
void end() { done = true; }
|
void end() { done = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,21 +4,24 @@
|
|||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
#include "Window/Window.h"
|
#include "Window/Window.h"
|
||||||
|
|
||||||
class GuiModule : Module {
|
namespace Archimedes {
|
||||||
|
|
||||||
|
class GuiModule : public Module {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef GuiModule* create_t();
|
typedef GuiModule* create_t(void*, App&);
|
||||||
|
|
||||||
GuiModule(void* h, App& a) : Module(h, a) {
|
GuiModule(void* h, App& a) : Module(h, a) {}
|
||||||
deps["Window"] = "";
|
|
||||||
}
|
|
||||||
virtual ~GuiModule() {}
|
virtual ~GuiModule() {}
|
||||||
virtual void load() = 0;
|
virtual void onLoad() = 0;
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
|
Window* getWindow() { return window; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Window window;
|
Window* window;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "pch.hpp"
|
#include "pch.hpp"
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
class App;
|
class App;
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
@@ -31,5 +33,6 @@ class Module {
|
|||||||
|
|
||||||
std::unordered_map<std::string, std::string> deps;
|
std::unordered_map<std::string, std::string> deps;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
App app(argc, argv);
|
Archimedes::App app(argc, argv);
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "Renderer.h"
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
void Renderer::render() {
|
||||||
|
r.render(rc, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
|
#ifndef RENDERER
|
||||||
|
#define RENDERER
|
||||||
|
|
||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
|
#define RENDERER_OPENGL
|
||||||
|
#include "RendererOpenGL/RendererOpenGL.h"
|
||||||
|
|
||||||
namespace Archimedes {
|
namespace Archimedes {
|
||||||
class Renderer {
|
class Renderer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int w, h;
|
||||||
typedef void renderCmd();
|
typedef void renderCmd();
|
||||||
|
|
||||||
~Renderer() {}
|
~Renderer() {}
|
||||||
@@ -14,6 +21,8 @@ namespace Archimedes {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<renderCmd*> rc;
|
std::list<renderCmd*> rc;
|
||||||
|
RendererImpl r;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#define RENDERER_OPENGL
|
||||||
|
#include "RendererOpenGL.h"
|
||||||
|
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
RendererOpenGL::RendererOpenGL() {}
|
||||||
|
|
||||||
|
RendererOpenGL::~RendererOpenGL() {}
|
||||||
|
|
||||||
|
void RendererOpenGL::render(std::list<renderCmd*> cmdList, int& w, int& h) {
|
||||||
|
|
||||||
|
glViewport(0, 0, &w, &h);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
for(auto* f : cmdList)
|
||||||
|
f();
|
||||||
|
cmdList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
#include "Renderer/Renderer.h"
|
#ifdef RENDERER_OPENGL
|
||||||
|
#undef RENDERER_OPENGL
|
||||||
|
|
||||||
|
#include "Archimedes.h"
|
||||||
|
|
||||||
namespace Archimedes {
|
namespace Archimedes {
|
||||||
|
|
||||||
class RendererOpenGL {
|
class RendererOpenGL {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef void renderCmd();
|
||||||
|
|
||||||
RendererOpenGL();
|
RendererOpenGL();
|
||||||
~RendererOpenGL();
|
~RendererOpenGL();
|
||||||
|
|
||||||
void render();
|
void render(std::list<renderCmd*>, int&, int&);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef RendererOpenGL RendererImpl;
|
typedef RendererOpenGL RendererImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1 +1,13 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
void Window::doFrame() {
|
||||||
|
window.getSize(renderer.w, renderer.h);
|
||||||
|
|
||||||
|
renderer.render();
|
||||||
|
|
||||||
|
window.doFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
#include "Renderer/Renderer.h"
|
#include "Renderer/Renderer.h"
|
||||||
#include "GLFW/WindowGLFW.h"
|
#include "WindowGLFW/WindowGLFW.h"
|
||||||
|
|
||||||
namespace Archimedes {
|
namespace Archimedes {
|
||||||
|
|
||||||
@@ -10,13 +10,16 @@ namespace Archimedes {
|
|||||||
|
|
||||||
~Window() {};
|
~Window() {};
|
||||||
|
|
||||||
bool shouldClose();
|
bool shouldClose() { return window.shouldClose(); }
|
||||||
|
|
||||||
void doFrame();
|
void doFrame();
|
||||||
|
|
||||||
|
Renderer& getRenderer() { return renderer; }
|
||||||
|
WindowImpl& getWindowImpl() { return window; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer renderer;
|
Renderer renderer;
|
||||||
|
|
||||||
WindowImpl w;
|
WindowImpl window;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(w);
|
glfwMakeContextCurrent(w);
|
||||||
|
glfwSwapInterval(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowGLFW::shouldClose() {
|
bool WindowGLFW::shouldClose() {
|
||||||
@@ -26,9 +27,8 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WindowGLFW::doFrame() {
|
void WindowGLFW::doFrame() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
glfwSwapBuffers(w);
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
glfwSwapBuffers(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowGLFW::~WindowGLFW() {
|
WindowGLFW::~WindowGLFW() {
|
||||||
@@ -15,6 +15,10 @@ namespace Archimedes {
|
|||||||
|
|
||||||
void doFrame();
|
void doFrame();
|
||||||
|
|
||||||
|
void getSize(int&, int&);
|
||||||
|
|
||||||
|
auto getWindow() { return w; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* w;
|
GLFWwindow* w;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user