diff --git a/modules/Window/src/WindowModule.cpp b/modules/Window/src/WindowModule.cpp index a32ff32..d404752 100644 --- a/modules/Window/src/WindowModule.cpp +++ b/modules/Window/src/WindowModule.cpp @@ -4,15 +4,9 @@ WindowModule::WindowModule(void* h, App& a) : Module(h, a) { name = "Window"; } -WindowModule::~WindowModule() { - delete window; - delete renderer; -} +WindowModule::~WindowModule() {} -void WindowModule::onLoad() { - window = new Window(); - renderer = new Renderer(); -} +void WindowModule::onLoad() {} void WindowModule::run() { diff --git a/modules/Window/src/WindowModule.h b/modules/Window/src/WindowModule.h index dc8f062..0fa336b 100644 --- a/modules/Window/src/WindowModule.h +++ b/modules/Window/src/WindowModule.h @@ -1,5 +1,5 @@ #include "Archimedes.h" -#include "WindowImpl/GLFW/windowGLFW.h" +#include "Window/Window.h" #include "Renderer/Renderer.h" class WindowModule : public Module { @@ -15,9 +15,7 @@ class WindowModule : public Module { private: - Window* window; - - Renderer* renderer; + Archimedes::Window window; }; diff --git a/utils/Renderer/Renderer.cpp b/utils/Renderer/Renderer.cpp new file mode 100644 index 0000000..e69de29 diff --git a/utils/Renderer/Renderer.h b/utils/Renderer/Renderer.h index 758a1e0..a8b1242 100644 --- a/utils/Renderer/Renderer.h +++ b/utils/Renderer/Renderer.h @@ -1,3 +1,19 @@ +#include "Archimedes.h" +namespace Archimedes { + class Renderer { + + public: + typedef void renderCmd(); + + ~Renderer() {} + + void render(); + + void addRenderCmd(renderCmd* cmd) { rc.push_back(cmd); } + + private: + std::list rc; + }; +} -class Renderer {}; diff --git a/utils/Renderer/RendererOpenGL/RendererOpenGL.h b/utils/Renderer/RendererOpenGL/RendererOpenGL.h index e69de29..c9303d7 100644 --- a/utils/Renderer/RendererOpenGL/RendererOpenGL.h +++ b/utils/Renderer/RendererOpenGL/RendererOpenGL.h @@ -0,0 +1,15 @@ +#include "Renderer/Renderer.h" + +namespace Archimedes { + + class RendererOpenGL { + + public: + RendererOpenGL(); + ~RendererOpenGL(); + + void render(); + }; + + typedef RendererOpenGL RendererImpl; +} diff --git a/utils/Window/GLFW/WindowGLFW.cpp b/utils/Window/GLFW/WindowGLFW.cpp new file mode 100644 index 0000000..cff6f6d --- /dev/null +++ b/utils/Window/GLFW/WindowGLFW.cpp @@ -0,0 +1,37 @@ +#include "Archimedes.h" +#include "WindowGLFW.h" + +namespace Archimedes { + WindowGLFW::WindowGLFW() { + + glfwSetErrorCallback([](int e, const char* m){ + std::cout << "GLFW Error: " << m << std::endl; + }); + if(!glfwInit()) { + std::cout << "glfwInit failed!\n"; + std::abort(); + } + w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL); + + if(!w) { + glfwTerminate(); + std::abort(); + } + + glfwMakeContextCurrent(w); + } + + bool WindowGLFW::shouldClose() { + return glfwWindowShouldClose(w); + } + + void WindowGLFW::doFrame() { + glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(w); + glfwPollEvents(); + } + + WindowGLFW::~WindowGLFW() { + glfwTerminate(); + } +} diff --git a/utils/Window/GLFW/WindowGLFW.h b/utils/Window/GLFW/WindowGLFW.h new file mode 100644 index 0000000..587f665 --- /dev/null +++ b/utils/Window/GLFW/WindowGLFW.h @@ -0,0 +1,23 @@ +#include "Archimedes.h" + +#include + +namespace Archimedes { + + class WindowGLFW { + + public: + + WindowGLFW(); + ~WindowGLFW(); + + bool shouldClose(); + + void doFrame(); + + private: + GLFWwindow* w; + }; + + typedef WindowGLFW WindowImpl; +} diff --git a/utils/Window/GLFW/windowGLFW.cpp b/utils/Window/GLFW/windowGLFW.cpp deleted file mode 100644 index f654359..0000000 --- a/utils/Window/GLFW/windowGLFW.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Archimedes.h" -#include "windowGLFW.h" - - -Window::Window() { - - glfwSetErrorCallback([](int e, const char* m){ - std::cout << "GLFW Error: " << m << std::endl; - }); - if(!glfwInit()) { - std::cout << "glfwInit failed!\n"; - std::abort(); - } - w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL); - - if(!w) { - glfwTerminate(); - std::abort(); - } - - glfwMakeContextCurrent(w); -} - -bool Window::shouldClose() { - return glfwWindowShouldClose(w); -} - -void Window::doFrame() { - glClear(GL_COLOR_BUFFER_BIT); - glfwSwapBuffers(w); - glfwPollEvents(); -} - -Window::~Window() { - glfwTerminate(); -} diff --git a/utils/Window/GLFW/windowGLFW.h b/utils/Window/GLFW/windowGLFW.h deleted file mode 100644 index 59fa488..0000000 --- a/utils/Window/GLFW/windowGLFW.h +++ /dev/null @@ -1,20 +0,0 @@ -#include "Window/Window.h" - -#define GLEW_STATIC -#include -#include - -class WindowGLFW : public Window { - - public: - - Window(); - ~Window(); - - bool shouldClose(); - - void doFrame(); - - private: - GLFWwindow* w; -}; diff --git a/utils/Window/Window.cpp b/utils/Window/Window.cpp new file mode 100644 index 0000000..ab55ba0 --- /dev/null +++ b/utils/Window/Window.cpp @@ -0,0 +1 @@ +#include "Window.h" diff --git a/utils/Window/Window.h b/utils/Window/Window.h index a5b6b34..03733ad 100644 --- a/utils/Window/Window.h +++ b/utils/Window/Window.h @@ -1,13 +1,22 @@ #include "Archimedes.h" +#include "Renderer/Renderer.h" +#include "GLFW/WindowGLFW.h" -class Window { +namespace Archimedes { - public: - - virtual ~Window() {}; + class Window { - virtual bool shouldClose() = 0; + public: - virtual void doFrame() = 0; + ~Window() {}; -}; + bool shouldClose(); + + void doFrame(); + + private: + Renderer renderer; + + WindowImpl w; + }; +}