66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#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
|