work on utils
This commit is contained in:
@@ -4,15 +4,9 @@ WindowModule::WindowModule(void* h, App& a) : Module(h, a) {
|
|||||||
name = "Window";
|
name = "Window";
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowModule::~WindowModule() {
|
WindowModule::~WindowModule() {}
|
||||||
delete window;
|
|
||||||
delete renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowModule::onLoad() {
|
void WindowModule::onLoad() {}
|
||||||
window = new Window();
|
|
||||||
renderer = new Renderer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowModule::run() {
|
void WindowModule::run() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
#include "WindowImpl/GLFW/windowGLFW.h"
|
#include "Window/Window.h"
|
||||||
#include "Renderer/Renderer.h"
|
#include "Renderer/Renderer.h"
|
||||||
|
|
||||||
class WindowModule : public Module {
|
class WindowModule : public Module {
|
||||||
@@ -15,9 +15,7 @@ class WindowModule : public Module {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Window* window;
|
Archimedes::Window window;
|
||||||
|
|
||||||
Renderer* renderer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
0
utils/Renderer/Renderer.cpp
Normal file
0
utils/Renderer/Renderer.cpp
Normal file
@@ -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<renderCmd*> rc;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class Renderer {};
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include "Renderer/Renderer.h"
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
class RendererOpenGL {
|
||||||
|
|
||||||
|
public:
|
||||||
|
RendererOpenGL();
|
||||||
|
~RendererOpenGL();
|
||||||
|
|
||||||
|
void render();
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef RendererOpenGL RendererImpl;
|
||||||
|
}
|
||||||
|
|||||||
37
utils/Window/GLFW/WindowGLFW.cpp
Normal file
37
utils/Window/GLFW/WindowGLFW.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
utils/Window/GLFW/WindowGLFW.h
Normal file
23
utils/Window/GLFW/WindowGLFW.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "Archimedes.h"
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
namespace Archimedes {
|
||||||
|
|
||||||
|
class WindowGLFW {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WindowGLFW();
|
||||||
|
~WindowGLFW();
|
||||||
|
|
||||||
|
bool shouldClose();
|
||||||
|
|
||||||
|
void doFrame();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GLFWwindow* w;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef WindowGLFW WindowImpl;
|
||||||
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#include "Window/Window.h"
|
|
||||||
|
|
||||||
#define GLEW_STATIC
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
class WindowGLFW : public Window {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Window();
|
|
||||||
~Window();
|
|
||||||
|
|
||||||
bool shouldClose();
|
|
||||||
|
|
||||||
void doFrame();
|
|
||||||
|
|
||||||
private:
|
|
||||||
GLFWwindow* w;
|
|
||||||
};
|
|
||||||
1
utils/Window/Window.cpp
Normal file
1
utils/Window/Window.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "Window.h"
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
#include "Renderer/Renderer.h"
|
||||||
|
#include "GLFW/WindowGLFW.h"
|
||||||
|
|
||||||
class Window {
|
namespace Archimedes {
|
||||||
|
|
||||||
public:
|
class Window {
|
||||||
|
|
||||||
virtual ~Window() {};
|
public:
|
||||||
|
|
||||||
virtual bool shouldClose() = 0;
|
~Window() {};
|
||||||
|
|
||||||
virtual void doFrame() = 0;
|
bool shouldClose();
|
||||||
|
|
||||||
};
|
void doFrame();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer renderer;
|
||||||
|
|
||||||
|
WindowImpl w;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user