move utils to include. utils implimentations should be headers
This commit is contained in:
18
include/utils/Window/Window.cpp
Normal file
18
include/utils/Window/Window.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
void Window::doFrame() {
|
||||
|
||||
window.pollEvents();
|
||||
|
||||
window.getSize(renderer.w, renderer.h);
|
||||
|
||||
renderer.render();
|
||||
|
||||
window.doFrame();
|
||||
}
|
||||
|
||||
}
|
||||
30
include/utils/Window/Window.h
Normal file
30
include/utils/Window/Window.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
|
||||
#include "Renderer/Renderer.h"
|
||||
#include "WindowGLFW/WindowGLFW.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Window {
|
||||
|
||||
public:
|
||||
|
||||
~Window() {};
|
||||
|
||||
bool shouldClose() { return window.shouldClose(); }
|
||||
|
||||
void doFrame();
|
||||
|
||||
Renderer& getRenderer() { return renderer; }
|
||||
WindowImpl& getWindowImpl() { return window; }
|
||||
|
||||
private:
|
||||
Renderer renderer;
|
||||
|
||||
WindowImpl window;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
65
include/utils/Window/WindowGLFW/WindowGLFW.h
Normal file
65
include/utils/Window/WindowGLFW/WindowGLFW.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#ifdef WINDOW_GLFW
|
||||
#undef WINDOW_GLFW
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class WindowGLFW {
|
||||
|
||||
public:
|
||||
|
||||
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();
|
||||
}
|
||||
std::cout << "Window Created!\n";
|
||||
glfwMakeContextCurrent(w);
|
||||
glfwSwapInterval(1);
|
||||
}
|
||||
|
||||
~WindowGLFW() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
bool shouldClose() {
|
||||
return glfwWindowShouldClose(w);
|
||||
}
|
||||
|
||||
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
|
||||
|
||||
void pollEvents() { glfwPollEvents(); }
|
||||
|
||||
void restoreContext() { glfwMakeContextCurrent(w); }
|
||||
|
||||
void getSize(int& w, int& h) {
|
||||
glfwGetFramebufferSize(this->w, &w, &h);
|
||||
}
|
||||
|
||||
GLFWwindow* getWindow() { return w; }
|
||||
|
||||
private:
|
||||
GLFWwindow* w;
|
||||
};
|
||||
|
||||
typedef WindowGLFW WindowImpl;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user