work on utils

This commit is contained in:
2025-03-21 13:38:31 -05:00
parent 719af8e85a
commit 7900def444
11 changed files with 113 additions and 76 deletions

View File

View 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 {};

View File

@@ -0,0 +1,15 @@
#include "Renderer/Renderer.h"
namespace Archimedes {
class RendererOpenGL {
public:
RendererOpenGL();
~RendererOpenGL();
void render();
};
typedef RendererOpenGL RendererImpl;
}

View 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();
}
}

View 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;
}

View File

@@ -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();
}

View File

@@ -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
View File

@@ -0,0 +1 @@
#include "Window.h"

View File

@@ -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;
};
}