#include #include "rendering/wrapper/Window.h" Window::Window(Size& size, Controller& controller, const Options& options) : window(nullptr), size(size), controller(controller) { glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, 0); glfwWindowHint(GLFW_RESIZABLE, 1); glfwWindowHint(GLFW_DECORATED, !options.fullscreen); glfwWindowHint(GLFW_DOUBLEBUFFER, 1); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); GLFWmonitor* monitor = options.fullscreen ? glfwGetPrimaryMonitor() : nullptr; window = glfwCreateWindow(size.width, size.height, options.name, monitor, nullptr); if(window == nullptr) { std::cout << "could not create window\n"; return; } glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwMakeContextCurrent(window); glfwSwapInterval(options.vsync); glfwSetWindowUserPointer(window, this); glfwSetFramebufferSizeCallback(window, [](GLFWwindow* glfwWindow, int newWidth, int newHeight) { glViewport(0, 0, newWidth, newHeight); void* data = glfwGetWindowUserPointer(glfwWindow); if(data == nullptr) { return; } Window& w = *static_cast (data); w.size.width = newWidth; w.size.height = newHeight; }); glfwSetKeyCallback(window, [](GLFWwindow* glfwWindow, int key, int, int action, int) { void* data = glfwGetWindowUserPointer(glfwWindow); if(data == nullptr) { return; } Window& w = *static_cast (data); if(action == GLFW_PRESS) { w.controller.press(key); } else if(action == GLFW_RELEASE) { w.controller.release(key); } }); } Window::~Window() { if(window != nullptr) { glfwDestroyWindow(window); } } bool Window::hasError() const { return window == nullptr; } void Window::show() { glfwShowWindow(window); } bool Window::shouldClose() const { return glfwWindowShouldClose(window); } void Window::swapBuffers() { glfwSwapBuffers(window); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }